Last active
July 25, 2016 17:52
-
-
Save jorgedfbranco/232691916e84fc7d6a8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://i.stack.imgur.com/BlpRb.png | |
whatis / whereis / which | |
ls | |
red results -> broken symlink | |
Get return value of last executed command: echo $? | |
Ignore error output: <command> 2>/dev/null | |
Open file and see its changes in real-time: tail -f <file> | |
Download: curl <url> (-L to follow redirects) | |
Send stderr to /dev/null: xpto 2>/dev/null | |
search by file contents: | |
egrep -ir --include=* <contents to search for> (you can use -lir instead of you just want the file names without the file contents) | |
diffs: | |
diff -u <new> <old> > my_patch.patch | |
patch < <path file> - a informacao sobre a q ficheiro aplicar o patch esta no .patch file | |
grep: | |
grep -oP "(?<=XPTO=).*" (the -o option makes grep ignore the XPTO= part and -P uses Perl regex). | |
"echo "XPTO=123" would then print "123" " | |
\K will make grep forget of whatever it matched until this point | |
-C x will show not only the found line, but as well the x above lines and x below lines too | |
-B x will show not only the found line, but as well the x prior lines | |
-A x will show not only the found line, but as well the x posterior lines | |
awk: | |
awk -F '/' '{print $1}' (split the string by the char /) | |
cut: | |
cut -c a-b (substring q vai do indice "a" a "b") | |
rev: | |
reverses all the lines of the given file | |
jar: | |
jar -tvf (lists the contents of the jar file) | |
apt: | |
remove -> removes but doesn't delete configuration | |
purge -> removes and deletes configuration | |
clean -> removes (unneeded) .deb installation files, freeing up disk space in the process. | |
autoremove -> removes the given program as well as dependencies it has that are not currently being used by any other application | |
cat: | |
cat -n <file> <- shows the file's contents with line numbers | |
downloads: | |
aria2c -x 16 <file> (downloads a file, dividing it in 16 segments that are downloaded concurrently) | |
find: | |
find -maxdepth <k> | |
find -regex <expr> | |
find -name \( "*.h" -or -name "*.c" \) <- we can compound flags with -and or -or. careful to surround stuff with ()'s. | |
readlink -f `which spotify` | |
pkill <process_name> <- kills all processes with that name | |
kill -9 `xprop _NET_WM_PID | awk '{print $3}'` <- kills the selected window | |
(sudo) pkill -U <username> <- kills all processes running under this username | |
less | |
-f <- follow (such as with tail) | |
h <- help | |
-i <- toggle case sensitivity | |
/ <- find pattern (may be regex) forward | |
n (forward) / N (backward) <- go to next/ previous match of the latest find pattern | |
? <- find pattern (may be regex) backward | |
n (backward) / N (forward) | |
f -> go forward one full screen | |
b -> go backward one full screen | |
Xj <- go X lines forward | |
Xk <- go X lines backward | |
&/ <- list all find results | |
------------------------------------------------------------------------------------------------ | |
ls - Lists directory contents. | |
------------------------------------------------------------------------------------------------ | |
Example: ls -l | |
Recommended Flags: -q, when in interactive mode. | |
------------------------------------------------------------------------------------------------ | |
Flags: | |
-1 - Show one file/directory result per line. | |
-t - Order results by "Modified time" descending. | |
------------------------------------------------------------------------------------------------ | |
bc - Calculator utility. Supports floating point arithmetic and arbitrary precision numbers. | |
------------------------------------------------------------------------------------------------ | |
Example: echo "1 + 2 * 3 ^ 4" | bc | |
Recommended Flags: -q, when in interactive mode. | |
------------------------------------------------------------------------------------------------ | |
Flags: | |
-q - Avoid showing welcoming message when in interactive mode | |
Commands: | |
obase=X - Sets the output base used by bc to X. Keep in mind that when defining both obase and ibase, obase | |
must always be defined first, otherwise strange behavior will ensue !! | |
ibase=Y - Sets the input base when interpreting numbers in bc to Y. | |
Other: | |
BC_LINE_LENGTH - bc will by default only show up to 70 sequential digits on a single line. If a given number is | |
will require more than that on any given line, the number will be truncated with \ and the rest | |
of the digits will be shown on the next line. To avoid that, you can set BC_LINE_LENGTH = 0. | |
------------------------------------------------------------------------------------------------ | |
watch - Allows to repeatedly run a given command. | |
------------------------------------------------------------------------------------------------ | |
Example: watch -n1 -td date | |
Recommended flags: -n1 -td | |
------------------------------------------------------------------------------------------------ | |
Flags: | |
-t - Avoid showing the default top line with the refresh rate and current time; | |
-d - Highlight differences between successive frames; | |
-nX - Set the refresh rate to X seconds. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment