- Signals
- Exit code
- kill
- top
- web
- wget
- curl
- files
- find
- grep
- compress/uncompress
- rsync
- history without line numbers
- hostname
- Ubuntu snap
- Proxy
- 3rd party
Signals¶
kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL ... 64) SIGRTMAX
Exit code¶
http://tldp.org/LDP/abs/html/exitcodes.html
1 Catchall for general errors
2 Misuse of shell builtins
126 Command invoked cannot execute
127 "command not found" illegal_command Possible problem with $PATH or a typo
128+n Fatal error signal "n"
kill -9 $PPID of script $? returns 137 (128 + 9)
130 Script terminated by Control-C
kill¶
pkill -KILL -u {username}
top¶
* 1 - Single Cpu Off (thus multiple cpus)
* c - Command line Off (name, not cmdline)
* i - Idle tasks On (show all tasks)
j - Str align right Off (not right justify)
V - Forest view On (show as branches)
f - sort/hide columns
(`*') could be overridden through the command-line.
web¶
wget¶
wget -O diff_name.zip http://...
curl¶
curl -O http://...
curl -o diff_name.zip http://
curl -sSL $1
-f, --fail Fail silently (no output at all) on HTTP errors (H)
-s, --silent Silent mode (don't output anything)
-S, --show-error Show error. With -s, make curl show errors when they occur
-L, --location Follow redirects (H)
-o, --output FILE Write to FILE instead of stdout
-O, --remote-name Write output to a file named as the remote file
files¶
String replace: http://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files
apt-get install mlocate
updatedb
locate -S
lsof -p <PID>
ls --help | grep -E '[-][tr]\b'
-r, --reverse reverse order while sorting
extension -X, size -S, time -t, version -v
-t sort by modification time, newest first
mkdir -p /not/existing/folder
cat > file <<'EOL'
EOL
ncdu --exclude='/root/data/*' /
du -hcd 2 / | more
du -a / | sort -n -r | head -n 20
ls -1 $PWD | wc -l # count files
file /bin/ps
ldd /bin/ps
find¶
find /home -iname tecmint.txt
find $1 -iname $2
# find . ! -readable / -writable / -executabl
# find . ! -perm -g=w
find -regextype posix-extended -regex ".*[.](py|sh)" -exec chmod +x {} \;
grep¶
grep --color=auto -rn -P "${regex}" ${path}
# -r, --recursive like --directories=recurse
# -n, --line-number print line number with output lines
# -P, --perl-regexp PATTERN is a Perl regular expression
compress/uncompress¶
gunzip file.gz
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file # Compress
tar -tvf my-data.tar.gz '*.py'
tar -zxvf toExtract.tar.gz
tar -xvf {tarball.tar} {special_file} -C /target/directory
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.
-t, --list list the contents of an archive
-j, --bzip2 filter the archive through bzip2
-c, --create create a new archive
-x, --extract, --get extract files from an archive
-z, --gzip, --gunzip, --ungzip filter the archive through gzip
-v, --verbose verbosely list files processed
-f, --file=ARCHIVE use archive file or device ARCHIVE
zip [options] zipfile files_list
-r recurse into directories
-x exclude the following names
-v verbose operation/print version info
-m move into zipfile (delete OS files) !!
-d delete entries in zipfile !!!
-u update: only changed or new files
xz --decompress file.xz # -dgrub # unxz
rsync¶
rsync -aP -e "ssh -p $3" $1 root@$2
rsync -aP /root/_bin root@remote:/root
rsync -aP -e "ssh -p 10220" /local root@remote:/dir --remove-source-files
-v, --verbose increase verbosity
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
-r, --recursive recurse into directories
-l, --links copy symlinks as symlinks
-p, --perms preserve permissions
-o, --owner preserve owner (super-user only)
-g, --group preserve group
-D same as --devices --specials
-t, --times preserve modification times
-S, --sparse handle sparse files efficiently
-e, --rsh=COMMAND specify the remote shell to use
--partial keep partially transferred files
--partial-dir=DIR put a partially transferred file into DIR
-z, --compress compress file data during the transfer
--progress show progress during transfer
-P same as --partial --progress
history without line numbers¶
history | cut -c 8-
-a append history lines from this session to the history file ~/.bash_history
hostname¶
hostnamectl set-hostname GZ2C8G
Ubuntu snap¶
run without root
Proxy¶
vi /etc/environment
systemctl restart snapd
3rd party¶
chromium --no-sandbox # start as root