Basics Linux commands (cheat sheet).

Basics Linux commands (cheat sheet).

1. File and Directory CRUD Navigation Commands CRUD stands for create read update delete.

Changing from user to Root

  • sudo <command>
    
  • sudo -i
    
  • sudo -su
    
  • sudo -s
    

1.pwd-(present working directory) - This commands shows in which directory or folder you are in.

  1. ls -(list all directories)- Lists all the files and directories inside the current directory as well as all the files and directories of the sub-directories as well.

  2. ls -R - Lists all the files and directories inside the current directory as well as all the files and directories of the sub-directories as well.

Note : you can type ls --help to find all commands you can use with ls . You can use same with every commands.

4.cd- This command is used to move to the root directory.

5.cd ~ - Same function as cd i.e. move to the root/home directory. Please note that there is a space between cd and tilde (~) symbol.

  1. cd ..- Move to one level up directory.

  2. cd dirName - Move to a particular directory from the current directory. Note that you can only move down the directory and not to the directories in the above level.

  3. mkdir - This command creates a directory.

  4. cat > fileName -This command creates a file in the current directory.

  5. cat fileName -This command displays the content in a file. If a file is not present in the current directory, it gives a message showing no such file exists.

  6. cat f1 f2 > f3 - This command joins the content of two files and stores it in the third file. If the third file does not exist, it is first created and then the joined content is stored.

  7. rmdir dirName - This command is the remove directory command. It deletes a directory.

  8. rmdir -R dirName - This commands is to remove directory in recursive manner. If directory is not empty.

  9. mv fileName “new file path” - This command is the move file command. It moves the file to the new path specified.

15 mv fileName newName - This command changes the name of the file from the old name i.e. the fileName to the newName.

16 . touch filname - This command to create an empty file.

17 . echo "your text" > filename - This command to insert text into that file.

2. System Information Commands

  1. history - This command displays the list of all the typed commands in the current
    terminal session.

  2. clear - Clears the terminal i.e. no previous command will be visible on the screen now.

3.hostname - Shows the name of the system host.

  1. hostid - Displays the id of the host of the system.

  2. sudo - Allows a regular user to run the programs with the security privileges of a superuser or root.

  3. apt-get - This command is used to install and add new packages.

  4. date - This command is used to show the current date and time.

  5. cal - Shows the calendar of the current month.

  6. whoami - This command displays the name with which you are logged in.

  7. whereis [options] fileName - This command is used to find the location of source/binary file of a command and manuals sections for a specified file in Linux System. This command is similar to the find command but this command is faster as it produces more accurate results by taking less time compared to the find command. There are again a number of options available.

3. File Permission Commands

There are 3 types of people who can use a file and each type has 3 types of access to the file.

File_Permission_Commands.png

The diagram shows that there are 3 types of people accessing a file and they are:

  1. User (u)
  2. Group (g)
  3. Others (o) Also, the access that we want to give to each of them is of three types:

    1. Read (r)
    2. Write (w)
  4. Execute (x)

here are some commands.

  1. ls -l - to show file type and access permission.

  2. r - read permission.

  3. w - write permission.

  4. x - Execute permission.

  5. Chown user - For changing the ownership of a file/directory.

  6. Chown user:group filename - change the user as well as group for a file or directory.

Note: if you want to change permission of files then use ``` chmod


# **4.User management commands of linux.**

1.

sudo adduser username ``` - To add a new user.

  1. sudo passwd -l 'username' - To change the password of a user.

  2. sudo userdel -r 'username' - To remove a newly created user.

  3. sudo usermod -a -G GROUPNAME USERNAME - To add a user to a group.

  4. sudo deluser USER GROUPNAME - To remove a user from a group.

  5. finger - Shows information of all the users logged in.

  6. finger username - Gives information of a particular user.

5. Networking command

  1. SSH username@ip-address or hostname - login into a remote Linux machine using SSH.

  2. Ping hostname="" or ="" - To ping and Analyzing network and host connections.

  3. dir - Display files in the current directory of a remote computer.

  4. cd "dirname" - change directory to “dirname” on a remote computer.

  5. put file - upload ‘file’ from local to remote computer.

  6. get file - Download ‘file’ from remote to local computer.

  7. quit - Logout.

Process command

  1. bg- To send a process to the background.
  2. fg - To run a stopped process in the foreground.
  3. top - Details on all Active Processes.
  4. ps - Give the status of processes running for a user.
  5. ps PID - Gives the status of a particular process.
  6. kill PID - Kills a process.
  7. df - Gives free hard disk space on your system.
  8. free - Gives free RAM on your system.

### These were the basic linux commands you should all know .