Title |
---|
Command line stuff |
ls [options] [paths]
Switch | Description |
---|---|
-1 |
One entry per line |
-l |
Long view |
-o |
Long view (without groups) |
-C |
Multicolumn (sorted horizontally) |
-x |
Multicolumn (sorted vertically) |
--- | |
-F |
Add / after directories |
-G |
Color |
{:.shortcuts} |
| -R
| Recurse |
| -a
| Include hidden (dotfiles) |
| -d */ | Only directories |
| -A
| Include hidden (but not . and ..) |
{:.shortcuts}
Switch | Description |
---|---|
-r |
reverse order |
-S |
sort by size |
-t |
sort by time modified |
-u |
sort by time accessed |
-U |
sort by time created |
-c |
sort by time status was changed |
--- | |
-h |
Human-readable size (3k) |
{:.shortcuts} |
ls -Cd */ # Only directories in column mode
ls -dl */ # Only directories in long view mode
ls -1d .* # List only files with .dot(hiddden)
ls -llt -tr # Sort order by date(most recent)
ls -lah -S -r # List order by size
tail [-F | -f | -r] [-bN | -cN | -nN] [file ...]
| -f
| follow |
| -F
| follow by filename (accounts for log rotation) |
| -r
| Reverse order |
{:.shortcuts}
| -bN
| N*512 bytes |
| -cN
| N bytes |
| -nN
| N lines |
| +N
| Start from line N |
{:.shortcuts}
$ df -h
find . -type f -name '*.xz' -mtime +30 -exec ls {}
sudo apt install ncdu
ncdu
brew install ncdu
ncdu
[root@tecmint]$ rsync -avz rpmpkgs/ root@192.168.0.101:/home/
root@192.168.0.101's password:
sending incremental file list
./
httpd-2.2.3-82.el5.centos.i386.rpm
...
[root@tecmint]# rsync -avzh root@192.168.0.100:/home/tarunika/rpmpkgs /tmp/myrpms
root@192.168.0.100's password:
receiving incremental file list
created directory /tmp/myrpms
rpmpkgs/
rpmpkgs/httpd-2.2.3-82.el5.centos.i386.rpm
...
[root@tecmint]# rsync -avzhe ssh root@192.168.0.100:/root/install.log /tmp/
root@192.168.0.100's password:
receiving incremental file list
install.log
sent 30 bytes received 8.12K bytes 1.48K bytes/sec
...
[root@tecmint]# rsync -avzhe ssh --progress /home/rpmpkgs root@192.168.0.100:/root/rpmpkgs
root@192.168.0.100's password:
sending incremental file list
created directory /root/rpmpkgs
rpmpkgs/
rpmpkgs/httpd-2.2.3-82.el5.centos.i386.rpm
1.02M 100% 2.72MB/s 0:00:00 (xfer#1, to-check=3/5)
sudo [options] <command>
| -l
| List allowed commands |
{:.shortcuts}
| -A
| Use $SUDO_ASKPASS |
| -b
| Run in background |
| -E
| Preserve environment |
| -H
| use target's $HOME |
| -n
| Don't prompt for password |
| -P
| Preserve group vector |
| -S
| Read password from stdin |
{:.shortcuts}
| -C fd
| Close all open file descriptors |
{:.shortcuts}
| -p prompt
| Custom prompt (-p "%p password:") |
{:.shortcuts}
Switch | Description |
---|---|
-i [cmd] |
Interactive shell without variables |
-s [cmd] |
Interactive shell |
---- | |
-u user |
run as this user |
-g group |
run as this group |
{:.shortcuts} |
| -v
| revalidate timestamp for 5 mins |
| -k
| invalidate timestamp |
| -K
| just like -k |
{:.shortcuts}
... | wc [options]
| -c
| Bytes |
| -l
| Lines |
| -m
| Characters (incl multi-byte) |
| -w
| Words |
{:.shortcuts}
# All folders
perl -p -i -e 's/hello/HELLO/g' **/*
# Specific file
perl -p -i -e 's/sending/receiving/g' tmux-client-57567.log
grep [options] [pattern] [file ...]
# find by filename
$ grep -rl "rahul" /home/
# Search text in a file
grep "FATAL" /var/log/syslog
# Search multiple strings
grep "FATAL|Warning|Error" /var/log/syslog
# Search in all files
grep "Error" /var/log/*
# Search in specific extension files
grep "rahul" /var/log/*.log
Switch | Description |
---|---|
-A num |
Print num lines of training context |
---- | |
-G |
--basic-regexp (default) |
-E |
--extended-regexp |
-P |
--perl-regexp |
---- | |
-f file |
--file (Get patterns for file) |
-F |
--fixed-strings |
---- | |
-h |
--no-filename |
-H |
--with-filename |
---- | |
-l |
--files-with-matches (just print filenames) |
-L |
--files-without-match |
---- | |
-r, -R |
--recursive |
-v |
--invert-match |
-i |
--ignore-case |
{:.shortcuts} |
egrep => grep -E
fgrep => grep -F
# Search string DHH with 3 rows extra informations
ag -C 3 DHH
# Search string in specify path
ag DHH guides/
# Search string in filesnames that contain the word action.
ag readme -l -G action
# Search string only to match filenames that end with ec.
ag readme -l -i -G ec$
# Search string with --ignore-dir Flag
ag readme -l --ignore-dir=railties/lib
# Search string in specific extension files(.rb)
ag create_table -C 3 -G .rb$
# Search string map in ruby files with line and column numbers
ag --ruby map --column
# List all file-types
ag --list-file-types
$ reboot
$ poweroff
$ shutdown -r 10 # Reboot server just after 10 minutes without displaying any message.
$ shudwown -r now # Reboot server immediately without any message.
# Reboot server at 02:10 AM with displaying proper message to user.
$ shutdown -r 02:10 "System is going to reboot..."