CLI Commands
Command line interface is used to interact with the system for giving the commands in to a terminal.
1.man : man command is used to give manual pages for various commands .
man [option] keyword
-k : Search for keywords in manual page names and descriptions.
-f: Display a concise description of the specified topics.
-a : Display all matching manual pages.
2.pwd : present working directory
pwd #pwd command is used to dispaly the present working directory.
3.cd : Change directory used to change the current directory
cd . #it represents the current directory
cd ~ #it moves to the home directory
cd / #it is used to change the current directory to root directory of file system
4.mkdir : mkdir is used to create a new directory.
mkdir dir_name
5.mv : mv is used to move the directory or file one place to another and used to rename.
mv path/to/source path/to/destination #moves the directory
mv filename newfilename #changes the file name
6.ls : ls command is used to list files and directories in a directory.
ls -l #use a long listing formate
ls -a #includes the hidden files and directories
ls -h #show file sizes in human-readable format (e.g., KB, MB).
ls -r #reverse the order of listing.
ls -t #sort by modification time, newest first.
7.cp : cp will copies the date from one file or directory in to another.
cp source_fname destination_fname #Copy a file to another location if
cp -r directory/ /path/to/destination/ #Copy a directory and its contents recursively
8.rm : rm is used to remove the file and non empty directories.
rm f_name #delete the file.
rm -r dir_name #deletes the non empty directory.
9.chmod : chmod is used to change the permissions of a file and directories for read(4),write(2),execute(1).
chmod u+r f_name #giving user to read permission
#before:pooja@pooja-IdeaPad-3-15ITL05:~$ ls -l f2.txt
#--w-rw-r-- 1 pooja pooja 24 Apr 24 11:33 f2.txt
#after:pooja@pooja-IdeaPad-3-15ITL05:~$ chmod u+r f2.txt
#pooja@pooja-IdeaPad-3-15ITL05:~$ ls -l f2.txt
#-rw-rw-r-- 1 pooja pooja 24 Apr 24 11:33 f2.txt
#here - :file, rw-:user perimission -rw :group permission -r-:other
chmod 777 dir_name or file_name #Giving permission read,write and execute to every one user,group,others
10.chown : chown is used to change the owner and/or group of files and directories.
sudo chown newuser:newgroup file.txt #Change both owner and group of a file:
#eg:pooja@pooja-IdeaPad-3-15ITL05:~$ chown user2:user2 f2.txt
sudo chown newuser:olduser file.txt
#pooja@pooja-IdeaPad-3-15ITL05:~$ ls -l f2.txt
#-rw-rw-r-- 1 pooja pooja 24 Apr 24 11:33 f2.txt
#pooja@pooja-IdeaPad-3-15ITL05:~$ sudo chown user2:pooja f2.txt
#[sudo] password for pooja:
#pooja@pooja-IdeaPad-3-15ITL05:~$ ls -l f2.txt
#-rw-rw-r-- 1 user2 pooja 24 Apr 24 11:33 f2.txt
11.sudo : it allows user to run command previleges.
sudo
12.apt : it is used to handle the package in linux.
sudo apt install
13.touch : it is used to create the file.
touch filename
14.cat : it is used to view the content of the file and copy the content of files in another using output redirection.
cat filename
cat f1_name f2_name >f3_name
15.less : it view the content of file page by page.
less filename
16.more : it view the text file line by line .
more filename
17.tail : it is used to give the last lines of the text file.
tail -n 4 filename
18.grep : it is used to search the matching pattern in file.
grep [option] pattern filename
19.find : it is used to find out the files or directory and certain pattern in filenames in directory.
find . -type f -name '*.txt' #it uses the files with .txt extension in cureent directory
find . -name 'fname' #it gives the fname file in current directory
20.sort : it is used to sort the content of the file.
sort filename
sort -r filename #sorts in reverse order
sort -u filename #removes the duplicates lines
21.tree: its shows the directories and files as tree structure based on their parents.
tree directoryname
OS/Process Related Commands
22.ps: process status provides information about the processes currently running on the system.
ps aux #it gives all process in detailed
ps -u "username" #it gives the all process of user
ps -o pid,ppid,pgid,sid #it gives current running process in terminal
ps -ef #it gives currently running processes in system
23.top : it is used to display a dynamic, real-time view of system resource usage. It provides a continually updated display of information about processes and system performance.
top
24.df : it is used to display the disk space.
df -h #gives the disk space usage in human readable
25.uname: it is used to display the os name.
uname
26.free : Used to check for memory usage and available memory.
free
27.lspci : it gives information about the audio drivers.
lspci
28.kill : Used to kill the running process.
kill <pid>
Network Related Commands
29.ping : it is used to test the network connection in server.
ping www.google.com
30.ifconfig : it is used to display detailed information about network interface and local ip.
curl ifconfig.me
31.ssh : it is used to securely connect to a remote system or server over a network. It stands for "Secure Shell" and is a standard method for remote login and secure communication between machines.
ssh username@hostname
Bash Realated Commands:
32.xargs : it takes the output of one command and gives as input.
touch "file1 file2 file3" | xargs ls -l
33.nano : it opens the nano editor.
nano filename
34.awk : it is used to print the specific columns and the matching pattern.
awk '{ print $1, $3 }' fname.txt
35.sed : it is used for the substitute.
sed 's/a/h/g' fname #it substitute the a with h character
36.Pipe operator : it is used to connect the output of one command to the input of another command.
cat fname | grep "a" #cat reads the file and grep find a in file