This article is for Basic Linux Commands or UNIX commands which are used every day by Linux user or development engineers to kick start with Linux. As of my knowledge, we should at least know these commands, or else we can not work in the Linux environment. If you are searching for any deep knowledge or more commands please search it in my blogging page I have explained it in another article.
I don’t want to waste the time let’s go start with :
Linux File related commands:
- The below Linux Command will take you to the ‘/ home‘ directory. No matter you are in which directory you can go to your home directory.
cd /home
2. The below Linux Command will take you to the go back one level:
cd ..
3. The df Linux Command is used to show the amount of disk space that is free on file systems
df
4. Linux ‘cd‘ (Change Directory) command is one of the most important and most widely used commands for newbies as well as system administrators.
cd ../..
5. cd command in Linux known as change directory command. It is used to change the current working directory.
cd
6. This Linux Command is used to the user’s home directory.
cd~user
7. This Linux Command takes you to the previous directory
cd –
Linux copy related commands:
8. This command is used to copy files or group of files or directory.
cp file1 file2
9. Copy all files of a directory within the current work directory
cp dir/* .
10. copy a data direct within the current work directory
cp -a /tmp/dir1 .
11. Copy a directory
cp -a dir1 dir2
12. Outputs the mime type of the file as text
cp file file1
Linux Commands about Symlink
13. Linux Command to create a symbolic link to file
ln -s file1 Ink1
Open a physical link to the file or directory
ln file1 Ink1
14. Open files directory
ls
15. Open files of directory
ls -F
16. Show the details of files and directory
ls -l
17. Open the hidden files
ls -a
18. Show the files and directory containing to the numbers
ls *[0-9]*
19. Show files and directories in a tree starting from root
lstree
20. Create a directory called ‘prakash’
mkdir prakash
21. How to create multiple directories simultaneously
mkdir dir1 dir2
22. How to create directory tree
mkdir -p /tmp/dir1/dir2
23. How to Move a Directory
mv dir/file / new_path
24. Show the path of work directory
pwd
25. How to delete a file called ‘file1‘
rm -f file1
26. Remove a directory called ‘dir1’ and contents recursively
rm -rf dir1
27. By using this below command you can remove two directories and their contents recursively
rm -rf dir1 dir2
28. Delete directory called ‘dir1’
rmdir dir1
29. Modify timestamp of a file or directory – (YYMMDDhhmm)
touch -t 0712250000 file1
30. Show files and directories in a tree starting from root(1)
tree
Linux Commands for Process Management
31. The top command gives you information on the processes that currently exist.
top
32. The htop command is like top, but prettier and smarter.
htop
33. Use the ps command to list running processes (top and htop list all processes whether active or inactive).
ps
34. A step up from the simple ps command, pstree is used to display a tree diagram of processes that also shows relationships that exist between them.
pstree
35. The who command will display a list of all the users currently logged into your Linux system.
who
36. As its name suggests, kill can be used to terminate a process with extreme prejudice.
kill
37. The pkill and killall commands can kill a process, given its name.
pkill & killall
38. pgrep returns the process IDs that match it.
pgrep
39. With the help of nice command, users can set or change the priorities of processes in Linux.
nice
40. It is similar to the nice command. Use this command to change the priority of an already running process.
renice
41. Gives the Process ID (PID) of a process
pidof
42. Gives free hard disk space on your system
df
43. Gives free RAM on your system
free
File Permissions
44. chmod the command for changing permissions
chmod 755 Linux_Directory
chmod 644 Linux_File
Different File Permissions
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx – – – – – – = 111 000 000
rwx = 111 in binary = 7
rw – = 110 in binary = 6
r – x = 101 in binary = 5
r – – = 100 in bunary = 4
7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)
Briefing about Permissions in Linux
There is huge importance with Linux Commands when we discuss Permissions. No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
777 (rwxrwxrwx)
The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
755 ( rwxr – xr – x )
The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
700 ( rwx – – – – – – )
All users may read and write the file.
666 ( rw – rw – rw – )
The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
644 ( rw – r – – r – – )
The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
600 ( rw – – – – – – – )
How to use “Find Command”
The below Linux Commands gives you better Idea on find commands. You can also check more Find Commands in our other article too.
45. To find a file by name
find -name “File1”
46. To find a file by name, but ignore the case of the “File1”
find -iname “File1”
47. To search all files that end in “.conf”
find /path -type f -name ” * . conf “
48. To find all files that are exactly 50 bytes
find /path -size 50c
49. To find all files less than 50 bytes
find /path -size -50c
50. To Find all files more than 700 Megabytes
find / -size +700M
51. To find files that have a modification time of a day ago
find / -mtime 1
52. To find files that were accessed in less than a day ago
find / -atime -1
53. To find files that last had their meta-information changed more than 3 days ago.
find / -ctime +3
54. To find files that were accessed in less than a minute ago
find / -mmin -1
55. If we want to match an exact set of permissions
find / -perm 644
56. If we want to specify anything with at least those permissions
find / -prem -644
Linux Commands to check Word Count
57. Prints the number of lines in a file.
wc – l file_name OR cat file_name | wc – l
58. Prints the number of words in a file.
wc – w
59. Displays the count of bytes in a file.
wc – c
60. Prints the count of characters from a file.
wc – m
61. Prints only the length of the longest line in a file.
wc – L
Compression Commands (tar, tar.gz, tar.bz2 and zip
Options to use the above Linux Commands
- c – create a archive file.
- x – extract a archive file.
- v – show the progress of archive file.
- f – filename of archive file.
- t – viewing content of archive file.
- j – filter archive through bzip2.
- z – filter archive through gzip.
- r – append or update files/directories to existing archive file.
- w – verify a archive file.
About TAR Command
62. About TAR Command
tar – cvf compress . tar / path / directory
63. To List Content of tar Archive File
tar – tvf compress . tar
64. To Untar tar Archive File
tar – xvf compress . tar
65. To Untar tar Archive File in a specific directory
tar -xvf compress . tar – c / path / to directory
66. Untar Single file from tar File
tar – xvf compress . tar file1 . txt
67. Untar Multiple files from tar
tar – xvf compress .tar ” file 1″ ” file 2″
68. Extract Group of Files using Wildcard from tar Archive
tar – xvf compress . tar – – wildcards ‘ * . txt’
69. To Add Files or Directories to tar Archive File
tar – rvf compress . tar file / dir
About TAR.GZ
70. To Create tar.gz Archive File
tar – cvzf compresstar . gz path/directory
71. To List Content tar.gz Archive File
tar – tvf compress . tar . gz
72. To Untar tar.gz Archive File
tar – zxvf compress . tar . gz
73. To Untar tar.gz Archive File in a specific directory
tar – zxvf compress . tar. gz – c / path / to directory
74. Untar Single file from tar.gz File
tar – zxvf compress . tar. gz file1 . txt
75. Untar Multiple files from tar.gz
tar – zxvf compress . tar. gz “file 1″ ” file 2″
76. Extract Group of Files using Wildcard from tar.gz Archive
tar – zxvf compress . tar. gz – – wildcards ‘ * . tzt ‘
77. To Add Files or Directories to tar.gz
tar – rvf compres . tar . gz file / dir
About TAR.BZ2
78. To Create tar.bz2 Archive File
tar – cvfj compress . tar . bz2 / path / directory
79. To List Content tar.bz2 Archive File
tar – tvf compress . tar . bz2
80. To Uncompress tar.bz2 Archive File
tar – xvf compress . tar . bz2
81. Untar Single file from tar.bz2 File
tar – jxvf compress . tar . bz2 file 1 . txt
82. Untar Multiple files from tar.bz2
tar – jxvf compress . tar . bz2 ” file 1″ “file 2 “
83. Extract Group of Files using Wildcard from tar.bz2 Archive
tar – jxvf compress . tar . bz2 – – wildcards ‘* . txt’
84. To Add Files or Directories to tar.bz2
tar – rvf compress . tar . bz2 file / dir
85. To Verify tar, tar.gz and tar.bz2 Archive File
tar – tvfW compress . tar
Linux Commands for ZIP
ZIP (The extension .zip is not mandatory and this is useful only to identify the file zip file)
86. To zipping a file or folder.
zip compress . zip file 1 file 2 folder 1
87. To Zip individual files to a zip archive
zip compres . zip file 1 file 2 file 3
Zipping a folder is a tricky thing as by default zip will not zip entire folder content such as subfolders and files
88. To zip the first level of folder content use * as shown below
zip compress . zip folder / *
89. If there are sub folders and files in 1 folder, in order to zip all content of a folder use -r option
zip – r compress . zip folder
90. To list all the files stored in a zip file. Any of the below commands can be used and they give the same results.
unzip – l compress . zip
less compress . zip
zipinfo – 1 compress . zip
91. To delete a file in an archive without extracting the entire zip file.
zip – d compress . zip path / to / file
92. To extract your files from a zip folder.
unzip compress . zip
93. To extract to a specific directory used option
unzip compress . zip – d / destination
94. To extract a specific file from an archive
unzip compress . zip test . sh
Linux Commands for Special Attributes on Files
95. Allows write the opening of a file only append mode
chattr +a file1
96. Allows that a file is compressed/decompressed automatically by the kernel
chattr +c file1
97. Makes sure that the program ignores Dump the files during backup
chattr +d file1
98. Makes it an immutable file, which can not be removed, altered, renamed or linked
chattr +i file1
99. Allows a file to delete safely
chattr +s file1
100. Makes sure that if a file is modified changes are written in the synchronous mode as with sync
chattr +S file1
101. Allows you to recover the contents of a file even if it is canceled
chattr +u file1
102. Allows you to recover the contents of a file even if it is canceled
lsattr file / folder
Linux Commands to know System Information
103. To know only system name, you can use the uname command
uname
104. To view your network hostname
uname – n
105. To get information about kernel-version
uname – v
106. To get the information about your kernel release
uname – r
107. To get the information about your kernel release
uname – r
108. To print your machine hardware name
uname – m
109. All this information can be printed at once. The below two commands gives the same result.
uname – a
cat / proc / version
110. Find out information about the Linux distribution and version
cat / etc / * release*
111. To gather information about file system partitions
fdisk -l
112. To view mounted file systems.
mount
113. To view information about your CPU architecture such as a number of CPU’s, cores, CPU family model, CPU caches, threads, etc. Either of the two below Linux Commands gives the same output.
lscpu
cat / proc / cpuinfo
114. To view information about block devices
lsblk
Extract Information about Hardware Components using “dmidecode“
115. To print information about memory. You can get a similar output with all the below commands.
dmidecode – t memory
cat / proc / meminfo
free or free – mt or free – gt
116. To print information about system
dmidecode – t system
117. To print information about BIOS
dmidecode – t bios
118. To print information about processor
dmidecode – t processer
119. To dump all hardware information
dmidecode | less
Network Commands
120. PING (Packet Internet Groper) command sends packet requests to the address you specify to test the connectivity between 2 nodes.
ping IP / hostname
121. Ifconfig utility is used to configure network interface parameters. Mostly we use this command to check the IP address assigned to the system.
ifconfig – a
122. traceroute print the route packets take to network host. Destination host or IP is mandatory parameter to use this utility
traceroute website.com / IP
123. route command is the tool used to display or modify the routeing table.
route
124. dig (Domain Information Groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name servers.
dig website.com
125. Whois To know the information about domain like
whois website.com
126. Host Command to find name to IP or IP to name
host hostname
host 1 . 2 . 3 . 4
127. telnet connect destination host:port via a telnet protocol if connection establishes means connectivity between two hosts is working fine.
telnet website.com 80
128. Tracepath traces the path of the network to the destination you have provided. It attempts to list the series of hosts through which your packets travel on their way to a given destination
tracepath website.com
129. nslookup is a program to query Internet domain name servers.
nslookup website.com
130. netstat command allows you a simple way to review each of your network connections and open sockets. netstat with head output is very helpful while performing web server troubleshooting.
netstat
131. scp allows you to secure copy files to and from another host in the network.
scp – r – p 22 (ssh port) user @ source_ hostname : / path / to / dir / destination / path
132. nmap is a very powerful command, which checks the opened port on the server.
nmap hostname – p 80
SSH Commands
133. Connect to host as user
ssh user@host
134. connect to host on port
ssh – p port user@host
KeyBoard Shortcuts
135. Halts the current command
ctrl+C
136. Stops the current Linux Command, resume with fg in the foreground or bg in the background
ctrl+Z
137. Log out of current session, similar to exit
ctrl+D
138. Erases one word in the current line
ctrl+W
139. Erases the whole line
ctrl+U
140. Type to bring up a recent command. You need to type the first letter of the command you are searching for.
ctrl+R
141. Log out of current session
exit
htop