Command Line Interface (CLI)
This blog provides an overview of command-line interface (CLI) commands commonly used in Unix-based operating systems such as Linux and Ubuntu. These commands allow you to perform a variety of tasks directly from the terminal. Below are several commands and their primary uses:
List of Commands
1.man
The man command is used to display the manual pages for other commands, providing detailed information about their usage, options, and operation.
example :
man cp
-> (Provides details on how to use the cp command to copy files and directories)
2.cd
The
cd
command stands for "change directory," is used to navigate between folders in Unix-based operating systems. This command changes the current working directory, allowing users to move around the file system.example :
cd Documents
-> (Moves the current directory to the Documents folder)cd ..
-> (Moves up one directory level)cd /
-> (Changes the current directory to the root directory)cd ~
->(Navigates to the user's home directory)
3.mkdir
The
mkdir
command is used to create new directories in Unix-based operating systems. It stands for "make directory," and it allows you to establish new folders in your file system from the command line.example :
mkdir first_folder
-> (Creates a new directory named 'first_folder' in the current directory)
4.mv
The
mv
command in Unix-based operating systems is used for moving files from one location to another or for renaming files. It stands for "move," and it can also effectively change the name of a directory.example :
mv a.txt ./second_folder
-> (Moves the file a.txt from its current location into the directory second_folder)mv a.txt b.txt
-> (Renames the file a.txt to b.txt)
5.cp with recursive flag
The
cp
command in Unix-based operating systems is used to copy files and directories. When you use the -r or --recursive flag with cp, it enables the copying of directories and their contents, including all subdirectories and files.example :
cp -r /path/to/folder /path/to/destination
-> (Copies the entire folder from the source path to the destination path, including all files and subfolders)
6.ls
The
ls
command is used to list the all the directories and files present in the that directoryexample:
ls Desktop
-> (shows all the files and directories that are present in the Desktop)
7.pwd
The
pwd
command stands for "present working directory" is used to show the what is the present working directory that we are working inexample :
pwd
-> (shows the path of the present working directory)
8.rm
The
rm
command in Unix-based operating systems is used to remove (delete) files and directories. However, it's important to use this command with caution because once a file is deleted using rm, it typically cannot be easily recovered.example :
rm a.txt
-> (it will remove the a.txt file in the directory)rm -r myfolder
-> (Removes the directory myfolder and all of its contents, including all subdirectories and files within it)
9.chmod
The
chmod
command in Unix-based operating systems is used to change the file mode bits (permissions) of files and directories. The permissions determine the actions that users can perform on a file or directory. These numbers represent the permissions for the owner, group, and others, respectively.(4: Read permission,2: Write permission,1: Execute permission,1:No permission)example :
chmod 777 a.txt
10.chown
The
chown
command in Unix-based operating systems is used to change the owner and group ownership of files and directories. It stands for "change owner," and it allows you to set or modify the user or group that owns a file or directory.example :
chown aman myfile.txt
-> (his command changes the owner ofmyfile.txt
to the useraman
)
11.sudo
The
sudo
command in Unix-based operating systems stands for "superuser do." It allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.example :
sudo apt update
-> (This command runsapt update
with root which is necessary for updating the package)
12.apt
The
apt
command, which stands for "Advanced Package Tool," is used on Ubuntu-based Linux distributions to manage packages. It manages software by automating the installation, upgrade, and removal of software packages.example :
sudo apt install nginx
-> (Installs thenginx
package and all its dependencies)
13.touch
The
touch
command is used to create the filesexample :
touch a.txt
-> (It will create the a.txt file in the current directory)
14.cat
The
cat
command is used to print the content in the filesexample :
cat a.txt
-> (It will print the content of the a.txt file in the console)
15.grep
The
grep
command in Unix-based operating systems is used to search for patterns in text data. It stands for "Global Regular Expression Print".example :
grep -c "unix" a.txt
-> (it will give the count of the "unix" word present in the a.txt file)
16.find
The
find
command is used to find the file and also for directoriesexample :
find . -name a.txt
-> (It will find the a.txt file and give the path of that file)
Subscribe to my newsletter
Read articles from SHARATH KUMAR directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by