gaurav0401 / Useful-Commands-in-Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Most used Linux Commands

  • touch used to create a new files like text files , media files.

  • cd used to change a directory/folder.

  • ls used to list all the files of a directory.

  • ls -l used to list files in long list format.

  • -m used to modifying a access time of file (eg. touch -m old.txt).

  • file used to check type of a file.

  • sudo apt update used to update package (advanced packaging tool).

  • rm used to remove files.

  • rm -i used to prevent files from accidently deletion by confirming before deletion.

  • rm -rf used to everything from directory.

  • cp used to copy a file.

  • mv used to moving or renaming a file.

  • head used to show specific content from a file from starting.

  • tail used to show specific content from a file from end. (Eg. tail -15 /dir1).

  • cat used to view and modifying a content of file. (Eg. cat file.txt or cat > file2.txt (for modifying)).

  • ls -la used to list all the files including hidden files.

  • pwd used to determined the location of currently working directory.

  • cd ~ used to go to the home directory.

  • cd.. used to go one directory back.

  • echo used to print

  • echo 'data' >> filename used to add content in a file

  • clear used to clear the screen.

  • append (>) used to append content to a file .

  • append (>>) used to append content to a file without overwriting.

  • grep used to search particular patterns in a file (i.e. filter).

  • pile (|) used to join two command.

  • ps This command shows all the running processes.

  • kill used to kill the process using process id (PID).

  • NOTE: you can use -9 to forcefully kill the app e.g kill -9 122.

Special Keys Stroke

  • Ctrl + C used to cancel the currently running command.

  • Ctrl +A move the cursor at the beginning of line.

  • Ctrl +B move the cursor backward one character.

  • Ctrl +E moves the cursor end of the line.

  • Ctrl + P pastes previous lines.

  • Ctrl + W delete the last word typed.

  • Ctrl + U delete the complete line.

  • Ctrl + R used for searching previously used commands.

  • Ctrl + S stops all output on screen.

Control Operators

  • ; used to operate more than one command in a line.

  • & (ampersand ) used to run command in a background.

  • && works as a logical AND (i.e run commands only if both command are correct otherwise shows error).

  • # used to comment**

  • history list all the commands used by the user.

Introduction to vi editor

  • vi used to create new file (ie vi filename) [Note: use Esc key then press ":wq" to save file and exit editor].
  • vi -R filename used open file in read-only mode.
  • view filename used to view file.

Basic Linux Tools

  • sleep used to suspend execution for a specific number of seconds.
  • cal used to show calendar.
  • date used to show date.
  • time used to summarize the execution time of a command.

Shell Scripting in Linux

  • A shell file is created with .sh extension (i.e. vim myscript.sh).
  • add #! /bin/bash at the starting .
  • To run script use sh file.sh command.

User management in Linux

  • /etc/passswd contains the information about user account and their passwords.
  • /etc/shadow contains the information about user passwords in encrypted form.
  • /etc/group contains the information about groupss.
  • /etc/gshadow contains the information about secure group.

File permissions

  • r read -- denoted with 4
  • w write -- denoted with 2
  • x execute -- denoted with 1
  • chmod used to change permission [e.g chmod u+rw file.txt ]

NOTE: strings command is used to read binary files e.g strings /bin/pwd

About