Linux Commands For Interview

1.pwd – Print Working Directory:

Example: Display the current working directory.
command:   pwd
Output: /home/your_username

2.ls – List Files and Directories:
Example: List files and directories in the current directory.
command: ls
Output:
file1.txt file2.txt directory1 directory2

3.cd-Change Directory:
Example: Change to the home directory.
command: cd ~
Now you re in the home directory.

4.mkdir-Make Directory:
Example: Create a new directory named “documents”.
command: mkdir documents

5.touch -Create Empty File:
Example: Create a new empty file named “example.txt”.
command: touch example.txt

6.cp-Copy Files or Directories:
Example: Copy a file from one location to another.
command: cp sourcefile destination

example : cp example.txt documents/

7.mv-Move (Rename) Files or Directories:
Example: Move a file to a different location or rename it.
mv oldfile newfile
mv example.txt newlocation/

8.rm-Remove Files or Directories:
Example: Delete a file named “unwanted.txt”.
rm unwanted.txt

9.cat-Concatenate and Display File Content:
Example: Display the contents of a file named “example.txt”.
cat example.txt
Output:
This is the content of example.txt.

10.man– Display Manual Pages:
Example:Get information about the ls command.
command : man ls
(Use arrow keys to navigate, press q to exit)

11.grep -Search Text in Files:
Example: Search for the word “error” in a log file.
command: grep “error” logfile.txt

12.find-Search for Files and Directories:
Example:Find all .txt files in the current directory and its subdirectories.

command: find . -name ” .txt”

13.ps-Display Information about Running Processes:
Example: List all running processes.
ps aux

14.kill-Terminate a Process:
Example: Terminate a process with a specific process ID.
kill -9 <process_id>

15.chmod-Change File Permissions:
Example: Give read and write permissions to the owner of a file.
chmod u+rw filename

16.df-Display Disk Space Usage:
Example: Show disk space usage for all mounted filesystems.
df -h

17.du -Display File and Directory Space Usage:
Example: Show the sizes of directories in the current location.

du -h –max-depth=1

18.tar – Create or Extract Tarballs:
Example: Create a compressed tarball of a directory.

tar -czvf archive.tar.gz directory/

19.ssh-Secure Shell:
Example:Connect to a remote server.

ssh username@remote_server

20.top-Display System Activity in Real Time:
Example: Display real-time information about CPU and memory usage.

top

Leave a Reply

Your email address will not be published. Required fields are marked *