Linux Commands
cd
cd
: directs to/home
cd ..
: Goes to parent of current directorycd /folder
: using absolute paths,folder
start from the root folder/
cd /mnt
: Mount Drivescd folder
: Goes to folderfolder
in this directoryexplorer.exe .
: opens in windows file explorer (WSL)
ls
ls
: Lists all folders in this directoryls -al
: Gives more informationYou have, from left to right:
- the file permissions (and if your system supports ACLs, you get an ACL flag as well)
- the number of links to that file
- the owner of the file
- the group of the file
- the file size in bytes
- the file modified datetime
- the file name
Note
- This set of data is also generated by the
l
option. - The
a
option instead also shows the hidden files. Hidden files are files that start with a dot (.) - For file permission : r = read , w = write , x = executions access
mkdir
mkdir folder
: creates folder namedabc
mkdir folder1 folder2
: creates multiple folders at oncemkdir -p folder/nested_folder
: creates_ _multiple nested folders by adding the-p
option
rm | rmdir
rm file
: deletes filermdir folder
: _deletes_ folder (The folder you delete must be empty.)rm -rf folder
: deletes files and folders and everything included
touch
touch abc
: creates an empty file (If the file already exists, silently fails)
mv
mv abc new_abc
: if there is no folder ,abc
will be renamed tonew_abc
. Otherwiseabc
will be moved to that foldermv a1 a2 abc
: movesa1
,a2
files to folderabc
pwd
pwd
: prints current path
chmod
chmod
: changes read write execute permissions (Details)
cat
cat in1
orcat < in1
: Reads filecat > in1
: Writes to file and thenctrl+c
to exit editingcat >> in1
: Appends to file and thenctrl+c
to exit editingcat -n in1
: prints content ofin1
with line numberscat in1 in2
: print contents of multiple filescat < in1 > in2
concatenate contents of single file into new filecat in1 in2 > in3
: concatenate contents of multiple files into new filecat in3 | anothercommand
: add another command using|
head | tail
head -n file_name
: prints first n linestail -n file_name
: prints last n lines
wc
word count
wc -l file1
: count lineswc -w file1
: count wordswc -c file1
: count characterswc -m file1
: count characters with multibyte support (i.e. emojis count as 1, not as multiple characters)wc -m in*
: operate wc -m on all files starting within
find
find . -name '*.txt'
: Finds all files with.txt
extensionfind . -name 'in*'
: Finds all files and folders starting with infind . -type d -name "in"
: search only directoryfind . -type f -name "in"
: search only filesfind . -type l -name "in"
: search only linksfind . -type f -name 'in*' -mtime +3
: Search files edited more than 3 days agofind . -type f -name 'in*' -mtime -1
: Search files edited in the last 24 hoursfind . -type f -mtime -1 -delete
: delete those who meet the criteriasfind . -type f -size +100c
: search files that have more than 100 characters (bytes) in themfind . -type f -size +100k -size -1M
: search file size bigger than 100KB but smaller than 1MB
find . -type f -exec cat {} \;
execute a command on each result of the search . {} is filled with the file name at execution time.