50 Basic Linux Commands
1) whoami
---> Shows the userame of the present user.
2) man command
---> Shows the manual for whichever command(like sudo, apt-get etc) you type.
3) CTRL + c
---> Stops any running command.
4) CTRL + a
---> Goes to the start of the line.
5) CTRL + e
---> Goes to the end of the line.
6) env
---> Shows environment variables.
7) $PATH
---> Shows executable search path.
8) $HOME
---> Shows Home directory.
# Directory Operations
9) pwd
---> Present Working Directory. Shows the current directory you are in.
10) mkdir {dir}
---> Make Directory. It creates a directory named {dir}.
Note: Don't include second bracket.
11) cd {dir}
---> Change Directory. Suppose you want to go to www folder in var. Then write cd /var/www/ .
12) cd ..
---> Goes one directory earlier. For example if you are in www folder and write this command then after this you will be in var folder.
13) pwd
---> Present Working Directory. Shows the current directory you are in.
14) ls
---> Lists the files and folders in the present directory. Doesn't shows Hidden files and folder.
15) ls -a
---> Shows all files and folder including hidden.
16) ls -l
---> Shows all files and folder in a long listing format (in details).
17) ls -al or ls -la
---> Shows all files and folder including hidden in a long listing format (in details).
# Search Files
18) find {dir} -name name*
---> Searches the {dir} directory for any file with the name.
19) find {dir} -user username
---> Searches the {dir} directory for any file owned by the "username" user.
20) locate {file_name}
---> Searches the file in the system.
# File Operations
21) touch {file_name}
---> Creates a file name file. Note: Don't use second bracket.
22) cat {file_name1} {file_name2}
---> Concatenates file1 into file2.
23) file {file_name}
---> To get the type of file1.
24) cp file_name1 file_name2
---> copies file1 to file2.
25) mv file_name1 file_name2
---> Moves file1 to file2. You can also use this to rename a file or folder or anything. There is no other dedicated command for renaming.
26) rm {file_name/folder_name}
---> Removes or deletes the file or folder.
27) rm -r {file_name/folder_name}
---> if the folder is not empty but you want to delete it anyway then use this.
28) rm -r *
---> caution: Never Ever use this command. This will delete every file or directory you have in your pc.
29) cp {dir1} {dir2}
---> Copies directory {dir1} to directory {dir2} or files from one directory to other
30) cp -r {dir1} {dir2}
---> Copies from dir1 to dir2 and if dir2 isn't there then creates the directory.
31) mv {dir1} {dir2}
---> Moves one file or directory to other file or other directory.
32) rm -rf dir
---> Force removes a directory.
# File Permissions
33) chmod 775 file_name
---> Changes the mode of the file to 775. What does 775 means? It is explained below.
34) chmod -R 400 folder
---> Recursively change mode of folder to 600. Yeah, I know. meanig of all this number are explained below.
35) chown owner_name file_name
---> Changes the owner of the file_name to owner_name(which can be a user).
# File Permissions Magic Numbers
4 -----> Read(r)
2 -----> Write(w)
1 -----> Execute(x)
When you use ls -la then at first column you wil see something like rw, rwx, wx this type of thing beside a folder or file. What rw means is that it has read and write permision, rwx means it has read, write and execution permission.
Now the magic numbers have 3 digits.
First digit signifies what permission the owner have.
Second digit signifies what permission any group have.
Third digit signifies what permission everyone else have.
For example:
400 means:
-> Owner have read permission.
-> Group doesn't have any permission.
-> Everyone else also doesn't have any permission.
765 means:
-> Owner have read,write and execute(rwx) permission.
-> Group have reda and write(rw) permission.
-> Everyone else have read and execute (rx) permission.
# How to use tar , zip and unzip
compress using tar:
36) tar -cvf {archive_name} file_name1 filename_2
Here an archive named archive_name is compressed with the file_name1 and filename_2.
Extract archive:
37) tar -xvf {archive name}
Before using zip and unzip command you must have zip and unzip uilities installed.
To install zip and unzip type in terminal:
38) sudo apt install zip
39) sudo apt install unzip
sudo is used for root permission. Wnever you use sudo you will require to give password.
zipping:
40) zip zip_file_name file1 file2 file3 file4...
This commands zips all the files listed into zip_file_name.
41) zip file_name.zip *.txt
This commands zips all the text files in the current directories into file_name.zip.
42) zip /path/to/directory/zip_file_name.zip filename
This command zips filename file into the given directory as zip_file_name.
43) zip -e zip_file filename
This command creates a password protected zip file.
44) zip -r file_name.zip folder1 folder2
This command zips folder1 and folder2.
Unzipping:
45) unzip file_name.zip
This command unzips the file into current directory.
46) unzip zip_file_name -d /path/to/directory
This command unzips the file into given directory.
47) unzip -l zip_filename.zip
This command is used to list the content of the zip file.
# How to use diff, comm and cmp commands
48) diff file1 file2
This command tells you the exact differences between two file.
49) cmp file1 file2
This command tells you the line number in which there is differences between two file.
50) comm file1 file2
This command tells you all differences between two file in lot of detailes.
No comments