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
2. Change to a directory
cd <directory name>
cd data
, to enter/change to folder data.
3. List contents of a directory
ls
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 commandsls -la data
will give you all files including hidden files with permission.
4. create a directory
mkdir
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
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>
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
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
here we can understand difference between file1 and file2.
9. find files in the system
find -name hulk.txt
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
This gives all permission to file hulk.txt.
In 755
7
is user permission
5
is group permission
5
is others permissionfor example if you want change permission/restrict permission to only for you
chmod 700 hulk.txt
This is my first post , let me know how can i improve in upcoming posts
Top comments (4)
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.
Thanks for the input , will add to the content.
Great post, this might be a typo that you may want to fix,
diff file1 file 2
Thanks for notifying , it was a typo. Will fix it.