Skip to main content

Command Palette

Search for a command to run...

Linux Commands

Published
5 min readView as Markdown
Linux Commands
A

I am a DevOps engineer from India.


File Management Commands

Directory Navigation:

  1. pwd - Get the full path of the current working directory

     pwd
    

  2. cd -To change the directory from the current directory

     cd
    

  3. cd ~ -Navigate to the current users home directory

     cd ~
    

  4. cd . . -Navigate one step backward from the current directory

     cd ..
    


List files:

  1. ls -l -List the files and directories in the current directory in Long Format

     ls -l
    

  2. ls -ld <Directory Name> - List contents of the specific directory

     ls -ld
    

  3. ls -a - List all files including hidden files

     ls -a
    

  4. ls -F -Shows the "*" symbol at the end of the file which means its executable

     ls -F
    

  5. ls -lt -List the files with the most recently modified files showing at the top

     ld -lt
    

  6. ls -lh -List the file size in a human-readable format

     ls -lh
    

  7. tree -Generates a tree representation of the file system

     tree
    


File/directory create, copy and remove:

  1. mkdir - It is used to create a directory

     mkdir new_directory
    

  2. touch -It is used to create files in directories

     touch new_file
    

  3. cat -It is used to concatenate files and it is used to view file data

     cat new_file
    

  4. cp -r <original_directory/file> <Copied_directory/file> -It is used to copy files/directories recursively

     cp -r new_directory copied_directory
    

  5. rm -r <Directory/File name> -It is used to remove files/directories recursively

     rm -r copied_directory
    

  6. mv <original_directory/filename> <renamed_directory/filename> -It is used to rename the files

     mv new_directory renamed_directory
    


Modifying File Permissions:

Sign

Function

+

To add Permissions for the selected file

-

To remove Permissions for the selected file

  1. chmod o-x <File_name> - To remove other user permission

     chmod o-x chmod_file
    

  2. chmod o+x <File_name> -To add other user permission

     chmod o+x chmod_file
    

  3. chmod o=_wx <File_name> -To modify Other user permissions

     chmod o=wx chmod_file
    

  4. chmod 777 <File_name> -To modify owner, group, and other permissions using octet numbers

     chmod 777 chmod_file
    

  5. chmod 456 <File_name>

     chmod 456 chmod_file
    


Managing User:

  1. sudo adduser <username> -To create a new user

     sudo adduser dummy_user
    

  2. sudo passwd <username> -To change the password for the user

     sudo passwd dummy_user
    

  3. su - <username> -To switch user

     su - dummy_user
    

  4. sudo addgroup <groupname> -To create a new group

     sudo addgroup linux
    
  5. sudo adduser -g <groupname> <username> - To add user to a group

     sudo adduser -g linux dummy_user
    
  6. sudo adduser -G <groupname_1> <groupname_2> <username> - To add user to multiple groups

     sudo adduser -G linux linux_2 dummy_user
    
  7. sudo adduser -aG <newgroup> <username> - To append new group to the existing groups

     sudo adduser -aG linux_3 dummy_user
    
  8. sudo adduser -G <groupname> <username> - To add user to group while creating the group

     sudo adduser -G Git dummy_user
    

Change the Owner of the file:

  1. chown <username>: <groupname> <filename> - To change ownership of the file

  2. chown <username> <filename> -To change only user

  3. chgrp <groupname> <filename> -To change only group of file


Package Manager: apt - Advanced Package Tool

  1. apt search <packagename> - To search for the given package

  2. apt install <packagename> -To install a package

  3. apt remove <packagename> - To remove uninstalled packages


Editing Files in the CLI:

  1. vim <filename> - To edit a file

  2. Press "i" - After entering in the Vim editor you will be in command mode to insert/modify anything press key "i"

  3. Press "esc" -To switch back to command mode

  4. press "dd" -To delete a particular line

  5. Press "d10" -To delete the following 10 lines

  6. Press "A" -To jump to the end of the line and change to insert mode

  7. Press "o" -To jump to the start of the line

  8. Press "11G" -Go to the 11 line

  9. Press "/" -To search for a pattern

  10. press "n" -To jump to the next match

  11. press "N" -To jump to the previous match

  12. :wq -To write file to disk and quit Vim

  13. :q! -To Quit Vim without saving the changes


Pipe Command: |

Pipes the output of the previous command as an input to the following command


grep: Global search for regular expressions and print out

  1. history | grep sudo -Basically looks for any command that history provides as an output that has sudo word init

     history | grep sudo
    

Redirection: >

  1. history | grep cd > cd_commands.txt -It takes the output from the previous command and stores it in a file that you define

     history | grep cd > cd_commands.txt
    

  2. history | grep cd >> cd_commands.txt -It appends text to the end of the file

     history | grep cd >> cd_commands.txt
    


More from this blog

Abdul Firoz's blog

14 posts