whoami current user name
hostname current pc name
cat /etc/os-release - info about current system
getent group sudo | cut -d: -f4 - show all sudo users
su - user2 - switch between users
sudo chmod a+rwx folderName/* add all access to the folder
chown -R username directory - add full permission directory and to all files and directories in that directory
chowd -R u+rX directory - the same as previous
du -h show folder size with human readable mode
du -ch folder_name/ show folder size with total
du ~/go | sort -n -r | less show sorted folder name
du folder_name/ | sort -n -r | head -n 20 show only 20 sorted files
ls -1 | wc -l count total files in directory
ls | head -23 limit the number of files printed by ls
ls [a-l]* – list files that start with a letter from a to l
ls *.html *.js - list files with certain extensions
sort dogs.txt | uniq -d – show only duplicates
ln <original> <link> - create a hard link, the link will still contain the original file content even if you delete original file
ln -s <original> <link> – create soft link, if you remove original file it will broke the link
find . -name "*.js" | xargs du -sch - show size of all .js file in a current directory tree
locate -c file_name.txt - find file and count res
locale file_name.txt - find file by name
cat file1 file2 >> file3 – append the content of multiple files into a new file
cat -n file1 - see the line numbers(also, -s, -b options)
less <filename>- /[name] - searches foreword, ?[name] - searches backwards
tail -f /var/log/system.log – watches for file changes
tail -n 10 <filename>- print the last 10 lines
diff file1 file2 - [-y compare line by line][-u diff between version ] show difference of two files
grep -n document.getElementById index.md - find name in file
wc -l test.txt - count the line inside file
rm -rf * - remove all folders and files inside current folder
rm -rf folderName - delete a folder and its contents recursively
cp -r folderName newName - copy a folder and its contents recursively
less +G logfile - open the file and scroll to the end, convenient for logs that are added in real time
rename "s/netcdf_zip$/GRIB/" multi_level* - rename a bunch of files
gzip filename – compress the file, and append a .gz extension to it, the original file is deleted.
gzip -k filename – compress the file and leave orig. file intact
gzip -d filename.gz – decompress file
tar -cf archive.tar file1 file2 - create archive from files
tar -xf archive.tar -C directory – extract to a specific folder
tar -czf archive.tar.gz file1 file2 – create a gzipped archive
tar -xf archive.tar.gz – unzip archive
:101 - go to the line 101
G - to the end of document
gg - to the top of document
E - to the end of line
0 - to start of the line
:%d - delete all content
ZZ - in show mode save the file and exit from Vim
:%s/.txt/.txt_copy/g replace file extension from [.txt] to [.txt_copy]
:%s;/home/lib;/home/roman/lib;g - replace some long path
:set number - show line number from the left
:set nonumber - remove number line from the left
?Word - searching for the Word in the document [N or n for next result]
Ctrl + V - Visual block mode [d - delete all the selected text]
:s/foo/bar/gc - replace words foo to bar , c - confirm each substitution
:s/\<foo\>/bar/ - Substituting Whole Word
Great post. It will definitely be useful to me.