143 Basic Linux Commands With Examples
143 Basic Linux Commands With Examples
In this article you will learn most frequently used Basic Linux Commands
File Commands
1. The following Linux Command take you to the '/ home' directory
cd /home
cd ../..
cd
cd ~user
cd -
cp file1 file2
cp dir/* .
cp -a /tmp/dir1 .
10. Copy a directory
cp -a dir1 dir2
cp file file1
ln -s file1 lnk1
ln file1 lnk1
ls
ls -F
ls -l
ls *[0-9]*
lstree
mkdir dir1
mkdir -p /tmp/dir1/dir2
mv dir/file /new_path
pwd
rm -rf dir1
rmdir dir1
tree
currently exist.
top
33. The htop command is like top, but prettier and smarter.
htop
34. Use the ps command to list running processes (top and htop list all
ps
pstree
36. The who command will display a list of all the users currently logged
who
37. As its name suggests, kill can be used to terminate a process with
extreme prejudice.
kill
38. The pkill and killall commands can kill a process, given its name.
pgrep
40. With the help of nice command, users can set or change the priorities
of processes in Linux.
nice
renice
pidof
df
free
File Permissions
45. chmod the command for changing permissions
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)
Brie ng about Permissions in Linux
There is a huge importance with Linux Commands when we discuss
777 (rwxrwxrwx)
The le's owner may read, write, and execute the le. All others may
read and execute the le. This setting is common for programs that are
755 (rwxr-xr-x)
The le's owner may read, write, and execute the le. Nobody else has
any rights. This setting is useful for programs that only the owner may
700 (rwx------)
666 (rw-rw-rw-)
The owner may read and write a le, while all others may only read the
le. A common setting for data les that everybody may read, but only
644 (rw-r--r--)
The owner may read and write a le. All others have no rights. A
common setting for data les that the owner wants to keep private.
600 (rw-------)
You can also check more Find Commands in our other article too.
46. To nd a le by name
find / -mtime 1
find / -atime -1
54. To nd les that last had their meta information changed more than
3 days ago
find / -ctime +3
find / -mmin -1
wc -w
wc -c
wc -m
wc -L
About TAR.GZ
71. To Create tar.gz Archive File
About TAR.BZ2
79. To Create tar.bz2 Archive File
90. If there are sub folders and les in 1 folder, in order to zip all content
unzip -l compress.zip
less compress.zip
zipinfo -1 compress.zip
unzip compress.zip
chattr +a file1
97. Allows that a le is compressed / decompressed automatically by the
kernel
chattr +c file1
98. Makes sure that the program ignores Dump the les during backup
chattr +d file1
renamed or linked
chattr +i file1
chattr +s file1
chattr +S file1
chattr +u file1
lsattr file/folder
Linux Commands to know System
Information
104. To know only system name, you can use uname command
uname
uname -n
uname -v
uname -r
uname -r
uname -m
110. All this information can be printed at once. The below two
uname -a
cat /proc/version
111. Find out information about the Linux distribution and version
cat /etc/*release*
fdisk -l
mount
lscpu
cat /proc/cpuinfo
lsblk
116. To print information about memory. You can get the similar output
cat /proc/meminfo
dmidecode -t system
dmidecode -t bios
dmidecode -t processor
dmidecode | less
Network Commands
121. PING (Packet Internet Groper) command sends packet requests to
ping IP/hostname
ifconfig -a
traceroute website.com / IP
124. route command is the tool used to display or modify the routeing
table.
route
DNS name servers. It performs DNS lookups and displays the answers
dig website.com
whois website.com
host hostname
host 1.2.3.4
ne.
telnet website.com 80
130. Tracepath traces the path of the network to the destination you
have provided. It attempts to list the series of hosts through which your
tracepath website.com
nslookup website.com
132. netstat command allows you a simple way to review each of your
network connections and open sockets. netstat with head output is very
netstat
133. scp allows you to secure copy les to and from another host in the
network.
134. nmap is a very powerful command, which checks the opened port
on the server.
nmap hostname -p 80
SSH Commands
135. Connect to host as user
ssh user@host
KeyBoard Shortcuts
137. Halts the current command
Ctrl+C
in the background
Ctrl+Z
Ctrl+D
Ctrl+W
Ctrl+U
142. Type to bring up a recent command. You need to type the rst letter
exit
Conclusion
Hope you will get better with the Linux Commands we covered in this
Grep Commands
Putty Commands
Find Commands
cURL Commands
df Commands
SED Commands
Wget Commands
Rsync Commands