Shell Commands for File Management

Shell commands for file management:

 

  1. ls:
    • Example: ls
    • Description: Lists files and directories in the current directory.

 

  1. cd:
    • Example: cd /path/to/directory
    • Description: Changes the current directory to the specified directory.

 

  1. pwd:
    • Example: pwd
    • Description: Prints the current working directory.

 

  1. mkdir:
    • Example: mkdir new_directory
    • Description: Creates a new directory with the specified name.

 

  1. rmdir:
    • Example: rmdir empty_directory
    • Description: Removes an empty directory.

 

  1. rm:
    • Example: rm file.txt
    • Description: Removes a file.

 

  1. touch:
    • Example: touch file.txt
    • Description: Creates an empty file or updates the timestamp of an existing file.

 

  1. cp:
    • Example: cp file.txt /path/to/destination
    • Description: Copies a file to the specified destination.

 

  1. mv:
    • Example: mv file.txt /path/to/destination
    • Description: Moves a file to the specified destination or renames a file.

 

  1. cat:
    • Example: cat file.txt
    • Description: Displays the contents of a file.

 

  1. less:
    • Example: less file.txt
    • Description: Displays the contents of a file one page at a time.

 

  1. head:
    • Example: head -n 10 file.txt
    • Description: Displays the first few lines (default: 10 lines) of a file.

 

  1. tail:
    • Example: tail -n 5 file.txt
    • Description: Displays the last few lines (default: 10 lines) of a file.

 

  1. grep:
    • Example: grep "pattern" file.txt
    • Description: Searches for a pattern in a file.

 

  1. find:
    • Example: find /path/to/directory -name "file.txt"
    • Description: Searches for files and directories matching specific criteria.

 

  1. chmod:
    • Example: chmod 755 file.txt
    • Description: Changes the permissions of a file or directory.

 

  1. chown:
    • Example: chown user:group file.txt
    • Description: Changes the owner and group of a file or directory.

 

  1. chgrp:
    • Example: chgrp group file.txt
    • Description: Changes the group of a file or directory.

 

  1. ln:
    • Example: ln -s source_file.txt link.txt
    • Description: Creates a symbolic link to a file or directory.

 

  1. file:
    • Example: file file.txt
    • Description: Determines the file type.

 

  1. du:
    • Example: du -sh directory
    • Description: Estimates the disk space usage of a file or directory.

 

  1. df:
    • Example: df -h
    • Description: Displays disk space usage of file systems.

 

  1. zip:
    • Example: zip archive.zip file1.txt file2.txt
    • Description: Creates a compressed zip archive.

 

  1. unzip:
    • Example: unzip archive.zip
    • Description: Extracts files from a zip archive.

 

  1. tar:
    • Example: tar -czvf archive.tar.gz directory
    • Description: Creates or extracts files from a tar archive.

 

  1. wc:
    • Example: wc -l file.txt
    • Description: Counts the number of lines, words, and characters in a file.

 

  1. sort:
    • Example: sort file.txt
    • Description: Sorts lines in a file.

 

  1. cut:
    • Example: cut -f 2,4 -d ',' file.txt
    • Description: Cuts out selected fields or columns from a file.

 

  1. paste:
    • Example: paste file1.txt file2.txt
    • Description: Merges lines from multiple files.

 

  1. diff:
    • Example: diff file1.txt file2.txt
    • Description: Compares files line by line.

 

These are some commonly used shell commands for file management, along with examples to illustrate their usage. 


Posted

in

by

Tags: