Basic Linux Commands
- ls – List files and directories in the current directory. Example:
ls
Explanation: This command will display a list of files and directories in the current location. - pwd – Print working directory. Example:
pwd
Explanation: This command shows the path of the current directory you are in. - cd – Change directory. Example:
cd /home/user/documents
Explanation: This command changes the current directory to “/home/user/documents”. - mkdir – Make directory. Example:
mkdir new_folder
Explanation: This command creates a new directory named “new_folder” in the current directory. - rmdir – Remove directory. Example:
rmdir empty_folder
Explanation: This command deletes an empty directory named “empty_folder” from the current directory. - cp – Copy files or directories. Example:
cp file.txt /path/to/destination
Explanation: This command copies “file.txt” to the specified destination path. - mv – Move or rename files or directories. Example 1:
mv file.txt /path/to/destination
Explanation 1: This command moves “file.txt” to the specified destination path. Example 2:mv old_file.txt new_file.txt
Explanation 2: This command renames “old_file.txt” to “new_file.txt”. - rm – Remove files or directories. Example 1:
rm file.txt
Explanation 1: This command deletes the file named “file.txt”. Example 2:rm -r folder
Explanation 2: This command deletes the “folder” directory and all its contents recursively. - touch – Create an empty file or update the file’s timestamp. Example 1:
touch new_file.txt
Explanation 1: This command creates a new empty file named “new_file.txt”. Example 2:touch existing_file.txt
Explanation 2: This command updates the timestamp of the “existing_file.txt” without changing its content. - cat – Concatenate and display the content of files. Example:
cat file.txt
Explanation: This command displays the content of “file.txt” on the terminal. - more / less – Display the content of files page by page. Example:
less large_file.txt
Explanation: This command allows you to view the content of “large_file.txt” page by page, making it easier to read large files. - head – Display the beginning of a file. Example:
head file.txt
Explanation: This command shows the first few lines of “file.txt”. - tail – Display the end of a file. Example:
tail file.txt
Explanation: This command shows the last few lines of “file.txt”. - grep – Search for a pattern in files. Example:
grep "keyword" file.txt
Explanation: This command searches for the word “keyword” in “file.txt” and displays matching lines. - echo – Print a message or value to the terminal. Example:
echo "Hello, World!"
Explanation: This command prints the message “Hello, World!” to the terminal. - chmod – Change file permissions. Example:
chmod +x script.sh
Explanation: This command adds the executable permission to “script.sh”, allowing it to be run as a script. - chown – Change file ownership. Example:
chown user:group file.txt
Explanation: This command changes the owner and group of “file.txt” to the specified user and group. - ps – Display the currently running processes. Example:
ps aux
Explanation: This command shows a list of all running processes on the system along with additional details. - kill – Terminate a process. Example:
kill PID
Explanation: This command sends a termination signal to the process with the specified PID (Process ID). - top – Display dynamic real-time information about running processes. Example:
top
Explanation: This command provides a live view of the system’s processes, updating regularly.
These are just some of the most basic Linux commands. The Linux command line offers a plethora of powerful utilities and options to explore and master.
Leave a Reply
Want to join the discussion?Feel free to contribute!