Basic Linux Commands

Linux commands are the fundamental tools for interacting with the Linux operating system. Here are some of the most commonly used commands:

1.ls

Thelscommand lists directory contents.

ls                 # Lists files and directories in the current directory
    ls -l              # Lists in long format, showing permissions, ownership, and size
    ls -a              # Includes hidden files (those starting with .)

2.cd

Thecdcommand changes the current directory.

cd /home/user      # Changes to the specified directory
    cd ..              # Moves up one directory level
    cd ~               # Changes to the home directory

3.pwd

Thepwdcommand prints the current working directory.

pwd                # Displays the full path of the current directory

4.cp

Thecpcommand copies files or directories.

cp file1.txt file2.txt    # Copies file1.txt to file2.txt
    cp -r dir1/ dir2/               # Recursively copies directory dir1 to dir2

5.mv

Themvcommand moves or renames files and directories.

mv oldname.txt newname.txt    # Renames oldname.txt to newname.txt
    mv file.txt /path/to/directory/     # Moves file.txt to the specified directory

6.rm

Thermcommand removes files or directories.

rm file.txt          # Removes the specified file
    rm -r directory/    # Recursively removes the directory and its contents
    rm -f file.txt      # Forces removal without prompting

7.mkdir

Themkdircommand creates a new directory.

mkdir newdir    # Creates a new directory named newdir

8.rmdir

Thermdircommand removes empty directories.

rmdir emptydir    # Removes the specified empty directory

9.touch

Thetouchcommand creates an empty file or updates the timestamp of an existing file.

touch newfile.txt    # Creates a new empty file named newfile.txt

10.cat

Thecatcommand concatenates and displays file content.

cat file.txt    # Displays the content of file.txt

11.grep

Thegrepcommand searches for patterns within files.

grep "search_term" file.txt    # Searches for search_term in file.txt
    grep -r "search_term" /directory/     # Recursively searches in the specified directory

12.chmod

Thechmodcommand changes file permissions.

chmod 755 file.sh    # Sets read, write, and execute permissions for owner, and read and execute for group and others

13.chown

Thechowncommand changes file ownership.

chown user:group file.txt    # Changes ownership of file.txt to user and group

14.ps

Thepscommand displays currently running processes.

ps                 # Lists processes running in the current shell
    ps aux             # Lists all running processes with detailed information

15.kill

Thekillcommand sends a signal to terminate processes.

kill PID          # Sends the default SIGTERM signal to the process with the specified PID
    kill-9 PID # Forces termination with SIGKILL

You are here for...

I think you are here to get to know me.

🌐 Connect with me across platforms.

🤝 Hit me up on these links, and let's turn ideas into action!