DEV Community

loading...
Cover image for Essential Linux commands Every Dev should know !!

Essential Linux commands Every Dev should know !!

jino93 profile image Jino pl ・2 min read

There are tons of commands in every Linux distro.some of the basic commands every developer should know.

1. Check current path of the directory
  pwd
Enter fullscreen mode Exit fullscreen mode
2. Change to a directory
cd <directory name>
Enter fullscreen mode Exit fullscreen mode

cd data , to enter/change to folder data.

3. List contents of a directory
ls 
Enter fullscreen mode Exit fullscreen mode

ls data , will list files of data folder.
ls -a data , will also list hidden files in the data folder
ls -l data , will list files/folders in data folder with permission.
combining above two commands ls -la data will give you all files including hidden files with permission.

4. create a directory
mkdir 
Enter fullscreen mode Exit fullscreen mode

mkdir data will create data directory in current location.
mkdir -p data/video will create data directory and a video folder inside.
mkdir -p data/{video,music} will create data directory and video,music folder inside.

5. view content of a file
cat 
Enter fullscreen mode Exit fullscreen mode

cat hulk.txt , can view content of hulk.txt

6. edit a file

There are several ways we can edit file in Linux , most of the Linux distro will have vim editor. so we are looking into vim today.

vim <filename>
Enter fullscreen mode Exit fullscreen mode

type i for insert mode , make changes to current file.
press ESC button then type :wq to save the file.

7. search
grep "pattern" file
Enter fullscreen mode Exit fullscreen mode

grep "hulk" avangers.txt , will search for the
avangers.txt for the pattern "hulk".
grep -i "hulk" avangers.txt marvel.txt for case-insensitive search in multiple files.
grep -nr "hulk" data if you want to search a pattern in folder data.

8. find the difference between two files

diff command is used to find the difference between two files.

diff file1 file2
Enter fullscreen mode Exit fullscreen mode

here we can understand difference between file1 and file2.

9. find files in the system
find -name hulk.txt
Enter fullscreen mode Exit fullscreen mode

this command will find all the files named hulk.txt in the folder and sub-folder.

10. Changing permission of a file.
  • 4 - read permission
  • 2 - write permission
  • 1 - execute permission
  • 0 - no permission
chmod 755 hulk.txt
Enter fullscreen mode Exit fullscreen mode

This gives all permission to file hulk.txt.
In 755
7 is user permission
5 is group permission
5 is others permission

for example if you want change permission/restrict permission to only for you

chmod 700 hulk.txt 
Enter fullscreen mode Exit fullscreen mode

This is my first post , let me know how can i improve in upcoming posts

Discussion (4)

pic
Editor guide
Collapse
cmuralisree profile image
Chittoji Murali Sree Krishna

there are lot more text editors instead of vim, few distros will have nano pre-installed, and to create a file you can use touch filename later you can edit with favorite text editor,

ls -l will give all the permissions of the file, same as ls -al for hidden files too.

Collapse
jino93 profile image
Jino pl Author

Thanks for the input , will add to the content.

Collapse
rishirajpurohit profile image
Rishiraj Purohit

Great post, this might be a typo that you may want to fix,
diff file1 file 2

Collapse
jino93 profile image
Jino pl Author

Thanks for notifying , it was a typo. Will fix it.