Directory Commands list with explanation
ls: This command lists all files and directories in the current directory.
- Explanation: The
ls
command has various options like-a
(list all files including hidden),-l
(long listing format),-h
(human-readable file sizes), and more. - Example:
ls -la
(This will display all files including hidden ones and their details like permissions, number of links, owner, group, size, and time of last modification).
- Explanation: The
pwd: Stands for “Print Working Directory”. This command is used to display the path of the current directory you are in.
- Example:
pwd
(This will display the full path to the current directory).
- Example:
cd: Stands for “Change Directory”. This command is used to change the current directory.
- Example:
cd Documents
(This will change the current directory to the “Documents” directory).
- Example:
mkdir: Stands for “Make Directory”. This command is used to create a new directory.
- Example:
mkdir new_directory
(This will create a new directory called “new_directory”).
- Example:
rmdir: Stands for “Remove Directory”. This command is used to delete an empty directory.
- Example:
rmdir empty_directory
(This will remove an empty directory named “empty_directory”).
- Example:
rm -r: Removes a directory and its contents.
- Explanation: Be careful with this command as it deletes directories and files permanently.
- Example:
rm -r directory
(This will remove a directory named “directory” and its contents).
cp -r: Copies a directory.
- Example:
cp -r dir1 dir2
(This will copy a directory named “dir1” to a new directory named “dir2”).
- Example:
mv: Moves or renames directories.
- Example:
mv dir1 dir2
(This will move a directory named “dir1” into another directory named “dir2”). - Example:
mv dir1 dir3
(This will rename “dir1” to “dir3”).
- Example:
![](https://techwhizworld.com/wp-content/uploads/2023/06/linux-commands-3.jpg)
File Commands list with explanation
cat: Concatenates and displays files.
- Explanation: This command is used to display the content of files. It can also be used to create a new file or concatenate files.
- Example:
cat file.txt
(This will display the content of “file.txt”).
less: Views file content page by page.
- Explanation: This command is used to view the content of files page by page, which is especially useful when dealing with large files.
- Example:
less largefile.txt
(This will open the largefile.txt in a paging format).
head: Displays the beginning of a file.
- Explanation: This command displays the beginning of a file. By default, it shows the first 10 lines.
- Example:
head -n 20 file.txt
(This will display the first 20 lines of “file.txt”).
tail: Displays the end of a file.
- Explanation: The opposite of
head
,tail
displays the end of a file. It’s often used with the-f
option to monitor the addition of new lines to a file. - Example:
tail -f logfile.log
(This will display the new lines being added to “logfile.log” in real time).
- Explanation: The opposite of
touch: Creates a new file.
- Explanation: This command is used to create a new empty file.
- Example:
touch newfile.txt
(This will create a new file named “newfile.txt”).
cp: Copies files or directories.
- Explanation: This command is used to copy files or directories from one location to another.
- Example:
cp source.txt destination.txt
(This will copy the contents of “source.txt” to “destination.txt”).
mv: Moves or renames files.
- Explanation: This command is used for moving or renaming files and directories from one location to another.
- Example:
mv oldname.txt newname.txt
(This will rename the file “oldname.txt” to “newname.txt”).
rm: Removes files or directories.
- Explanation: This command is used to remove files or directories. Be careful when using this command, as it permanently deletes files.
- Example:
rm file.txt
(This will remove “file.txt”).
find: Searches for files in a directory hierarchy.
- Explanation: This command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.
- Example:
find /home -name myfile.txt
(This will search for a file named “myfile.txt” in the “/home” directory and its subdirectories).
grep: Searches for a text pattern within files.
- Explanation: This command is used to search inside files. With it, you can search for lines that contain certain strings within files.
- Example:
grep 'error' logfile.log
(This will display lines that contain the string ‘error’ in the “logfile.log”).
chmod: Changes file permissions.
- Explanation: This command is used to change the permissions of a file or directory.
- Example:
chmod 755 script.sh
(This will set the permission of “script.sh” to 755, which means the owner can read, write, and execute, and others can read and execute).
chown: Changes file ownership.
- Explanation: This command is used to change the ownership of a file or directory.
- Example:
chown username:groupname file.txt
(This will change the ownership of “file.txt” to the user “username” and the group “groupname”).
File Content Commands list with explanation
cat: Displays the content of a file.
- Explanation:
cat
is a standard Unix utility that concatenates and lists files. It can be used to show the contents of a file, concatenate the contents of multiple files, or even create a new file. - Example:
cat file.txt
(This will display the content of “file.txt”).
- Explanation:
less: Allows you to peruse through the contents of a file page by page.
- Explanation:
less
is used to view the content of files in a page by page manner, especially useful when dealing with large files. It also supports navigating forward and backward. - Example:
less file.txt
(This will allow you to scroll through the file “file.txt” page by page).
- Explanation:
more: Similar to less, allows file viewing page by page.
- Explanation:
more
is a command used to view the contents of a file in a page by page manner. The difference is thatmore
only allows forward navigation. - Example:
more file.txt
(This will display the content of “file.txt” page by page).
- Explanation:
head: Displays the beginning of a file.
- Explanation:
head
command is used to display the first part of the files. By default, it prints the first 10 lines of each file to standard output. - Example:
head -n 5 file.txt
(This will display the first 5 lines of “file.txt”).
- Explanation:
tail: Displays the end of a file.
- Explanation:
tail
command is used to display the last part of the files. By default, it prints the last 10 lines of each file to standard output. With-f
option, it will keep the file open and display appended data in real time. - Example:
tail -n 5 file.txt
(This will display the last 5 lines of “file.txt”).
- Explanation:
grep: Searches for a specific pattern within a file or files.
- Explanation:
grep
is used to search for a specific pattern in one or multiple files. It outputs the lines containing the pattern. - Example:
grep 'search_term' file.txt
(This will display lines in “file.txt” containing ‘search_term’).
- Explanation:
sed: Stream editor for filtering and transforming text.
- Explanation:
sed
(stream editor) is a Unix utility that parses and transforms text, using a simple, compact programming language. It can perform text substitutions, deletions, insertions and more. - Example:
sed 's/test/TEST/' file.txt
(This will replace the first occurrence of ‘test’ with ‘TEST’ in each line of “file.txt”).
- Explanation:
awk: Powerful text-processing language.
- Explanation:
awk
is a powerful scripting language that’s excellent at processing structured text/data. It can be used to manipulate data and generate reports. - Example:
awk '{print $1}' file.txt
(This will print the first field (column) from each line in “file.txt”).
- Explanation:
![](https://techwhizworld.com/wp-content/uploads/2023/06/linux-commands-2.jpg)
User Commands list with explanation
whoami: Displays the username of the current user.
- Explanation: This command is used to print the username associated with the current effective user ID.
- Example:
whoami
(This will display the username of the current user).
id: Displays the user and group IDs for a user.
- Explanation: This command is used to print the real and effective user ID and group IDs.
- Example:
id username
(This will display the user and group IDs of “username”).
su: Switches the current user to another user.
- Explanation: This command is used to change the current user ID or become superuser during a login session.
- Example:
su username
(This will switch the current user to “username”).
sudo: Executes a command as another user.
- Explanation: This command is used to run programs with the security privileges of another user (by default, as the superuser). It stands for “superuser do”.
- Example:
sudo apt-get update
(This will run the “apt-get update” command with root privileges).
useradd: Adds a new user.
- Explanation: This command is used to create a new user or update default new user information.
- Example:
sudo useradd newusername
(This will add a new user named “newusername”).
usermod: Modifies a user account.
- Explanation: This command is used to modify or change any attributes of a already created user account via command line.
- Example:
sudo usermod -aG sudo username
(This will add the user “username” to the “sudo” group).
userdel: Deletes a user account.
- Explanation: This command is used to delete a user account and related files.
- Example:
sudo userdel username
(This will delete the user account “username”).
passwd: Changes the password for a user.
- Explanation: This command is used to change the password of a user account. A normal user can only change the password for their own account, but the superuser can change the password for any account.
- Example:
passwd
(This will prompt you to enter a new password for the current user).
chown: Changes the owner of a file/directory.
- Explanation: This command is used to change the user and/or group ownership of a given file, directory, or symbolic link.
- Example:
sudo chown username:groupname file.txt
(This will change the owner of “file.txt” to “username” and the group to “groupname”).
groups: Shows the groups a user is a member of.
- Explanation: This command is used to show the groups a user is a member of.
- Example:
groups username
(This will show the groups that “username” is a part of).
Filter Commands list with explanation
grep: Searches for a pattern in files or input, returning lines that contain the pattern.
- Explanation: The
grep
command is one of the most frequently used UNIX command stands for ‘Global Regular Expression Print’. It searches the given file for lines containing a match to the given strings or words. - Example:
grep "error" logfile.txt
(This will print all lines in “logfile.txt” that contain the word “error”).
- Explanation: The
awk: Scans and processes text line by line and field by field.
- Explanation:
awk
is a powerful command for complex text processing. It scans text line by line, splitting each line into fields, and processes it according to provided script. - Example:
awk '{print $2}' file.txt
(This will print the second field of every line in “file.txt”).
- Explanation:
sed: Stream editor for filtering and transforming text.
- Explanation:
sed
is a stream editor that is used to perform basic text transformations on an input stream (a file or input from a pipeline). - Example:
sed 's/foo/bar/' file.txt
(This will replace the first occurrence of “foo” with “bar” in each line of “file.txt”).
- Explanation:
sort: Sorts the lines in a text file.
- Explanation: The
sort
command is used to sort lines in text files in a particular order. - Example:
sort file.txt
(This will sort the lines in “file.txt” in ascending order).
- Explanation: The
uniq: Reports or omits repeated lines.
- Explanation: The
uniq
command is used to filter out the repeated lines in a file. It is helpful for removing duplicate entries from a file. - Example:
sort file.txt | uniq
(This will remove duplicate lines in the sorted “file.txt”).
- Explanation: The
cut: Removes sections from each line of files.
- Explanation: The
cut
command is used to remove or “cut out” certain sections of each line in a file. - Example:
cut -d':' -f1 /etc/passwd
(This will display the usernames in the system, cutting at the delimiter “:” and displaying the first field).
- Explanation: The
wc: Prints newline, word, and byte counts for files.
- Explanation: The
wc
(word count) command in Unix/Linux is used to find out number of newline count, word count, byte and characters count in a files specified by the file arguments. - Example:
wc -l file.txt
(This will display the number of lines in “file.txt”).
- Explanation: The
head: Outputs the first part of files.
- Explanation: The
head
command, by default, shows the first 10 lines of each file name that is provided to it. - Example:
head -n 5 file.txt
(This will display the first 5 lines of “file.txt”).
- Explanation: The
tail: Outputs the last part of files.
- Explanation: The
tail
command, by default, shows the last 10 lines of each file name that is provided to it. - Example:
tail -n 5 file.txt
(This will display the last 5 lines of “file.txt”).
- Explanation: The
tee: Reads from standard input and writes to standard output and files.
Utility Commands list with explanation
-
ps: Lists the currently running processes.
- Explanation:
ps
stands for process status. It provides information about the currently running processes, including their process identification numbers (PIDs). - Example:
ps aux
(This will provide a snapshot of all current processes).
- Explanation:
-
top: Provides a real-time, dynamic view of the processes running in a system.
- Explanation:
top
command is used to get a dynamic real-time view of the running system. It provides a live, scrollable list of processes sorted by how much CPU they are using. - Example:
top
(This will display a real-time view of system processes).
- Explanation:
-
df: Reports the amount of disk space used on a file system.
- Explanation:
df
stands for “disk filesystem”. It reports file system disk space usage. - Example:
df -h
(This will display disk usage in a human-readable format).
- Explanation:
-
du: Estimates the disk usage of files and directories.
- Explanation:
du
stands for “disk usage”. This command is used to estimate and report the disk space used by files and directories. - Example:
du -sh /home/user
(This will display a summary, in human-readable format, of total disk space used within the specified directory).
- Explanation:
-
free: Shows the amount of free and used memory in the system.
- Explanation:
free
command is used to check the amount of free, used, swap memory in the system, along with the buffers used by the kernel. - Example:
free -m
(This will display the amount of free and used memory in megabytes).
- Explanation:
-
uptime: Shows the current time, how long the system has been running, how many users are currently logged on, and the system load averages.
- Explanation:
uptime
command gives a one-line display of the following information: The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. - Example:
uptime
(This will display the current uptime).
- Explanation:
-
history: Shows the command history.
- Explanation:
history
command is used to view the previously executed command. - Example:
history
(This will display your command history).
- Explanation:
-
clear: Clears the terminal screen.
- Explanation:
clear
command is used to clear the terminal screen. It doesn’t take any argument. - Example:
clear
(This will clear the terminal screen).
- Explanation:
-
date: Displays or sets the system date and time.
- Explanation:
date
command is used to display the system date and time.date
also can be used to set the date and time. - Example:
date
(This will display the current date and time).
- Explanation:
-
man: Displays the manual pages.
- Explanation:
man
stands for manual. This command is used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the command which includes NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS and SEE ALSO. - Example:
man ls
(This will display the manual pages for thels
command).
- Explanation:
-
echo: Outputs the strings it is being passed as arguments.
- Explanation:
echo
is a command in Linux that outputs its arguments. - Example:
echo "Hello, World!"
(This will print “Hello, World!” to the terminal).
- Explanation:
-
which: Shows the full path of shell commands.
- Explanation:
which
returns the pathnames of the files (or links) which would be executed in the current environment. - Example:
which ls
(This will show the full path of thels
command).
- Explanation:
-
clear: Clears the terminal screen.
- Explanation:
clear
is used to clear your terminal if it gets filled up with too many previous commands. - Example: Just type
clear
and press Enter to clear your terminal.
- Explanation:
-
history: Shows the command history.
- Explanation:
history
command is used to view the previously executed commands. - Example: Just type
history
and press Enter to view your command history.
- Explanation:
-
date: Displays the current date and time.
- Explanation:
date
command is used to display the system date and time.date
command is also used to set date and time of the system. - Example: Just type
date
and press Enter to view the current date and time.
- Explanation:
-
df: Reports the amount of available disk space.
- Explanation:
df
stands for “disk filesystem”, it is used to get full summary of available and used disk space usage of the file system on Linux system. - Example:
df -h
(This will display disk space usage in human-readable format).
- Explanation:
-
du: Estimates file and directory space usage.
- Explanation:
du
stands for “disk usage”, it is used to estimate and report file and directory space usage. - Example:
du -sh /home/user
(This will summarize the disk usage of the /home/user directory in human-readable format).
- Explanation:
-
free: Displays the amount of free and used memory in the system.
- Explanation:
free
command is used to check the amount of free, used, swap memory in KB. - Example:
free -h
(This will display memory details in human-readable format).
- Explanation:
-
top: Provides a dynamic real-time view of the running system.
- Explanation:
top
command is used to check the system process and load average on the system. - Example: Just type
top
and press Enter to view the real-time view of the running system.
- Explanation:
Networking Command list with explanation
ping: Sends ICMP ECHO_REQUEST packets to network hosts.
- Explanation:
ping
command is used to check the network connectivity between the host that sends the ping and the destination host. - Example:
ping google.com
(This will ping google.com and report back the response time).
- Explanation:
ifconfig: Displays or configures a network interface.
- Explanation:
ifconfig
(interface configurator) command is used to initialize an interface, assign IP Address to interface and enable or disable interface on demand. - Example:
ifconfig
(Running this without any options will display a list of network interfaces and their configuration).
- Explanation:
netstat: Network statistics. Shows network connections, routing tables, interface statistics, etc.
- Explanation:
netstat
(network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interface statistics. - Example:
netstat -tuln
(This will display only listening sockets with numerical addresses).
- Explanation:
ssh: Secure shell remote login protocol.
- Explanation:
ssh
(Secure Shell) is a protocol to log into another computer over a network, to execute commands in a remote machine, and to move files from one machine to another. It provides strong authentication and secure communications over unsecured channels. - Example:
ssh user@remotehost
(This will start a shell session on the remote host as user “user”).
- Explanation:
telnet: User interface to the TELNET protocol.
- Explanation:
telnet
is a user command and an underlying TCP/IP protocol for accessing remote computers. - Example:
telnet remotehost 23
(This will open a telnet connection to “remotehost” on port 23).
- Explanation:
traceroute: Print the route packets take to network host.
- Explanation:
traceroute
is a network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network. - Example:
traceroute google.com
(This will show the route that packets take to get to google.com from your machine).
- Explanation:
nslookup: Query Internet name servers interactively.
- Explanation:
nslookup
is a network administration command-line tool available for querying the Domain Name System (DNS) to obtain domain name or IP address mapping, or other DNS records. - Example:
nslookup google.com
(This will display DNS information for google.com).
- Explanation:
dig: DNS lookup utility.
- Explanation:
dig
(domain information groper) is a network administration command-line tool for querying DNS name servers. - Example:
dig google.com
(This will perform a DNS lookup for google.com).
- Explanation:
wget: Network downloader.
- Explanation:
wget
is a free utility for non-interactive download of files from the web. It supports HTTP, HTTPS, and FTP protocols. - Example:
wget https://example.com/file.txt
(This will download the file “file.txt” from the specified URL).
- Explanation:
curl: Transfers data from or to a server.
- Explanation:
curl
is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, IMAP, POP3, etc). - Example:
curl https://example.com
(This will fetch the content of the web page at the specified URL).
- Explanation: