Linux Commands

ls

List directory contents.

  • ls -l: Long listing format
  • ls -a: Show hidden files
  • ls -lh: Long listing with human-readable file sizes

Example: ls -l /home/user

cd

Change directory.

  • cd ..: Move up one directory
  • cd ~: Go to the home directory
  • cd /path/to/directory: Change to a specific directory

Example: cd /var/log

pwd

Print name of current/working directory.

  • This command takes no arguments.

Example: pwd

mkdir

Make directories.

  • mkdir new_directory: Create a new directory
  • mkdir -p parent/child: Create parent directory if it doesn't exist

Example: mkdir project_files

rm

Remove files or directories.

  • rm file.txt: Remove a file
  • rm -r directory: Remove a directory and its contents (recursive)
  • rm -f file.txt: Force removal without prompting

Example: rm old_report.doc

cp

Copy files and directories.

  • cp source.txt destination.txt: Copy file
  • cp -r source_dir destination_dir: Copy directory

Example: cp document.pdf /backup/

mv

Move (rename) files and directories.

  • mv old_name.txt new_name.txt: Rename file
  • mv file.txt /path/to/destination/: Move file to another directory

Example: mv draft.txt final_version.txt

cat

Concatenate files and print on the standard output.

  • cat file.txt: Display file content
  • cat file1.txt file2.txt > combined.txt: Combine files

Example: cat README.md

grep

Print lines matching a pattern.

  • grep "pattern" file.txt: Search for pattern in a file
  • grep -i "pattern" file.txt: Case-insensitive search
  • grep -r "pattern" directory/: Recursive search

Example: grep "error" /var/log/syslog

man

An interface to the on-line reference manuals.

  • man command_name: Display manual page for a command

Example: man ls