All about command line on Linux.
References:
- Art of Command Line
- How Linux Works
- Personal snippets
Softlinks are just a reference to a file path existing somewhere. Editing it, will not affect the file it's linked to.
Hardlinks in turn is a direct reference to the target file path, thus, editing it will also edit the file it's linked to.
ln -s file-path.txt ~/soft-symlinked-file.txtIf target file is deleted, soft symlinked file will still exist but will be broken.
ln file-path.txt ~/hard-symlinked-file.txtIf target file is deleted, hard links will still be there with the latest content.
ctrl-x ctrl-e will open the current command in an EDITOR for multi-line editing
nohup command &See also, jobs, disown, and command &
# do something in current dir
(cd /some/other/dir && other-command)
# continue in original dirdiff ~/some_file.txt <(ssh host && cat ~/some_file.txt)Few optimizations on SSH config. > settings contains config to avoid dropped connections in certain network environments, uses compression (which is helpful with scp over low-bandwidth connections), and multiplex channels to the same server with a local control file:
TCPKeepAlive=yes
ServerAliveInterval=15
ServerAliveCountMax=6
Compression=yes
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ControlPersist yesThis "Argument list too long" error is common when wildcard matching large numbers of files. (When this happens alternatives like find and xargs may help.)
Print data from gzip compressed files.
- Print the uncompressed contents of a gzipped file to the standard output:
zcat file.txt.gz
- Print compression details of a gzipped file to the standard output:
zcat -l file.txt.gzSee also zless, zmore, zgrep.
ack ag ripgrep
takes whitespace separated strings from stdin and converts into command-line arguments
echo "home tmp" | xargs ls
will run ls home tmp
xargs -n 1 will run a separate process per each input. Pass in -P n to set max number of parallel processes
tiny language to manipulate columns of data.
Example:
ps | awk -F, '{print $3}most often used for replacements
sed s/match/replace/g file.txtsed 5d # deletes the 5th linesed /cat/d # deletes the line matching catsed -n 5,30p # prints lines between 5 to 30sed 'i 17 panda' # insert panda on line 17sed G # double space a file-
Commands that start with
spacedoes not go to the history -
!! run the last command ran as sudo
-
ctrl + r : search history
-
ctrl + z : suspend a process,
fgto get back to it in foregroundbgin background -
fc: fix command, opens the last ran command in $EDITOR
du # tells how much diskspace a /directory occupies
-h # human readable format
-s # summary
df # tells the free space over each partitions
-h # human readable format
ncdu # interactive prompt going over files/directories showing the sizes
-h # human readable formatrerun commands intermittently (2 seconds by def)
calendar
paste contents into terminal from system clipboard
find common lines in two sorted files
figure out the mime details of the file
add timestamps
kill is not only used to kill processes. It can be used to send any signal to any program
list all signals
kills a process based on pattern matched and pid found
pkill -f firefox
signals all processes to be killed with NAME
useful flags:
- -w : wait for process to die
- -i : ask before signalling
cats a gzipped file
lists open files
lists open network sockets
lists deleted files
another way of showing open sockets