Skip to content

nkr38/Linux_Commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 

Repository files navigation

Linux_Commands

Useful Linux commands and their arguments

Basic commands

๐Ÿ”ธ cd /directory              moves the present working directory to one specified
๐Ÿ”ธ cp /copied_item /target    copies a filed or directory to a target directory. If your copying a directory use cp -rf . .
๐Ÿ”ธ pwd                        shows the absolute path of where you are (present working directory)
๐Ÿ”ธ chmod ### file             how you give or remove access to files. first digit is you, second is group and last is all users 
(read=4,write=2,execute=1. ex: use 777 for full access to everyone)
๐Ÿ”ธ diff /file /file           outputs the lines that do not match between the two files
๐Ÿ”ธ rm file                    remove command lets you remove a file. Removing a directory requires -rf (ex: rm -rf dir)
๐Ÿ”ธ mkdir directoryname        makes a directory with the name specified
๐Ÿ”ธ touch filename             makes a file with the name specified
๐Ÿ”ธ mv file file               lets you move a file somewhere else and is also used to rename files
๐Ÿ”ธ cat file                   displays the text of a file
๐Ÿ”ธ man "command"              displays the manual for the command specified. Useful to find options for the command quickly
๐Ÿ”ธ history                    shows the commands you've entered
๐Ÿ”ธ ctrl+c                     quits you out of most programs
๐Ÿ”ธ |                          this symbol is called "pipe" and is used to feed output of one command into another command without 
storing it into a variable (ex: "ls -s | head -5" takes the list of files ordered by size from ls and prints the top 5 of them)

ls

ls commands $ ls [options] [file|dir]

๐Ÿ”ธ ls -a          list all files including hidden file starting with '.'
๐Ÿ”ธ ls --color     colored list [=always/never/auto]
๐Ÿ”ธ ls -d          list directories
๐Ÿ”ธ ls -i          list file's inode index number
๐Ÿ”ธ ls -l          list with long format - show permissions
๐Ÿ”ธ ls -la         list long format including hidden files
๐Ÿ”ธ ls -lh         list long format with readable file size
๐Ÿ”ธ ls -ls         list with long format with file size
๐Ÿ”ธ ls -r          list in reverse order
๐Ÿ”ธ ls -R          list recursively directory tree
๐Ÿ”ธ ls -s          list file size
๐Ÿ”ธ ls -S          sort by file size
๐Ÿ”ธ ls -t          sort by time & date
๐Ÿ”ธ ls -X          sort by extension name

grep

grep commands grep [options] pattern [files]

๐Ÿ”ธ grep -c        This prints only a count of the lines that match a pattern
๐Ÿ”ธ grep -h        Display the matched lines, but do not display the filenames
๐Ÿ”ธ grep -i        Ignores, case for matching
๐Ÿ”ธ grep -l        Displays list of a filenames only
๐Ÿ”ธ grep -n        Display the matched lines and their line numbers
๐Ÿ”ธ grep -v        This prints out all the lines that do not matches the pattern
๐Ÿ”ธ grep -e exp    Specifies expression with this option. Can use multiple times
๐Ÿ”ธ grep -f file   Takes patterns from file, one per line
๐Ÿ”ธ grep -E        Treats pattern as an extended regular expression (ERE)
๐Ÿ”ธ grep -w        Match whole word      

sed

sed commands sed [option] 'command' [input-file]

๐Ÿ”ธ sed '/^$/d'    Remove all whitespace
๐Ÿ”ธ sed 's/Sonday/Sunday/' weekday.txt
๐Ÿ”ธ sed -i         When option, edit source file directly. Also used to ignore case when flag
๐Ÿ”ธ sed -g         Edit every occurence
๐Ÿ”ธ ^              Acts like a special character and matches at the beginning of the regular exp
๐Ÿ”ธ $              Acts like a special character and matches at the end of the regular exp 
๐Ÿ”ธ .              Matches any single character, even including a new line
๐Ÿ”ธ *              Matches the sequence of zero or more instances of the previous character
๐Ÿ”ธ sed 's/Linux/Unix/'  linuxteck.txt (first occurence in each line)
๐Ÿ”ธ sed 's/Linux/Unix/2' linuxteck.txt (Second occurence in each line)

sort

sort commands sort [OPTION]... [FILE]...

๐Ÿ”ธ sort -b        Remove all whitespace
๐Ÿ”ธ sort -d        Consider only blanks and alphanumeric characters
๐Ÿ”ธ sort -f        Fold lower case to upper case characters
๐Ÿ”ธ sort -g        Compare according to general numerical value
๐Ÿ”ธ sort -i        Consider only printable characters
๐Ÿ”ธ sort -n        Compare according to string numerical value

head/tail

head commands head [OPTION]... [FILE]...

๐Ÿ”ธ head -n #      Print number of lines from top down
๐Ÿ”ธ tail -#        prints last # of elements (lines/files)

About

Useful Linux commands and their arguments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages