Linux Basic Interactive Shell Command
Linux Basic Interactive Shell Command
Index
80%
20%
- terminal and shell shortcut key / shell interactive command
- File system
- cat cd chmod chown chgrp cksum cmp cp dd du df file fsck fuser ln ls lsattr lsof mkdir mount mv pax pwd rm rmdir size split tee touch type umask
- chmod chown chgrp cksum cmp dd fsck fuser ln ls lsattr lsof mv pax tee type umask
- Processes (All, used in Academia, and Engineering)
- at bg chroot cron fg kill killall nice pgrep pidof pkill ps pstree time top
- at chroot killall nice pgrep pidof pkill time top
- User environment
- clear env exit finger history id logname mesg passwd su sudo uptime talk tput uname w wall who whoami write
- Text processing
- awk banner basename comm csplit cut dirname ed ex fmt fold head iconv join less more paste sed sort spell strings tail tr uniq vi wc xargs
- Shell builtins
- alias echo expr printf sleep test true and false unset wait yes
- Networking
- dig host ifconfig inetd netcat netstat nslookup ping rdate rlogin route ssh traceroute
- Searching (done)
- find grep locate whatis whereis
- who
- Documentation
- Miscellaneous
- bc dc cal date lp lpr
- purge
- Other tools and
mail
, wget
, purge
zenity
- display GTK+ dialog
man ascii
- ASCII character set encoded in octal, decimal, and hexadecimal - Linux Programmer's Manual
screen
waiting 2013-05-06
Unknown category
- xclip - command line interface to X selections (clipboard)
hdparm
- get/set SATA/IDE device parameters
- Usage: SYNOPSIS
hdparm [options] [device ...]
- Description: hdparm provides a command line interface to various kernel interfaces supported by the Linux SATA/PATA/SAS "libata" subsystem and the older IDE driver subsystem. Many newer (2008 and later) USB drive enclosures now also support "SAT" (SCSI-ATA Command Translation) and therefore may also work with hdparm. E.g. recent WD "Passport" models and recent NexStar-3 enclosures. Some options may work correctly only with the latest kernels.
Content
Linux Terminal - Shell Command
Shell shortcut in Engineering
- LEONID MAMCHENKOV,Shell keyboard shortcuts
- Bash Shortcuts for Maximum Productivity
- Backward for a word
- Mac OS X: ALT(Option) + Left(Home)
- Beginning of the command line you currently typing on: CTRL + a
- Eng of the command line you currently typing on: CTRL + e
- End of stdin in the bash: CTRL+D
- Move backward one word: CTRL + b
- Move forward one word: CTRL + f
FS (File system)
- Index
- cat cd chmod chown chgrp cksum cmp cp dd du df file fsck fuser ln ls lsattr lsof mkdir mount mv pax pwd rm rmdir size split tee touch type umask
- chmod chown chgrp cksum cmp dd fsck fuser ln ls lsattr lsof mv pax tee type umask
cp (copy) / scp (secure copy)
- SCP (Secure Copy) - Wikipedia
- 1.Download file from remote server
- Command:
scp -P 2000 root@www.google.com:root/borg.tar.gz /home/borg.tar.gz
- P: Upper case "P" represent port, if you are not change the default SSH port, this won't be necessary
- root@www.google.com: use root to login to server
- ":": a symbol to separate the server address and file path
- root/borg.tar.gz: the file path and name on that server
- /home/borg.tar.gz: the file parth and name to save on your computer
- 2.Download directory from remote server
- Command:
scp -P 2000 -r root@www.google.com:root/borg/ /home/borg/
- same as abrove
- -r: recursive copy files and directories in the folder
- 3.Upload file to remote server
- Command:
scp -P 2000 /home/omega.tar.gz root@www.google.com
- you are smart, you will figure it out
- 4.Upload directory to remote server
- Command:
scp -P 2000 -r /home/omega/ root@www.google.com
- you are smart, you will crack it
- parameters
- -v: to display the progress, view the connection, configuration fault.
- -C: use compression.
- -4: force to use IPV4
- -6: force to use IPV6
FS: Directory operation (cd/pushd/popd, mkdir, rmdir)
cd
- change directory
pushd
/popd
: use to navigate during different directory
- pushd /mnt: navigate to /mnt and put current directory into stack
- popd: pop the top from stack and go to that directory
mkdir
- make new directory
rmdir
- delete a Empty directory
pwd
- Print the name of current/working directory
FS: File Operation (du/ df/ file)
cat
- output the file data on the screen
file
- determine file type
- Usage:
file "filename"
- Example:
file index
- Result: index.html: HTML document, UTF-8 Unicode text, with very long lines
size
- list section size and total size
- Example:
size a.out
- Result:
text data bss dec hex filename
1471 0504 016 1991 7c7 a.out
split
- split a file into pieces
- Note: Very useful to processing text file, more details, please excute command
man split
.
FS: Dir and File
FS: Filesystem operation (mount
/ umount
)
du
- estimate file space usage
- Example:
du -h index
- Result: 16K index.html,
-h
- human readable format
df
- report file system disk space usage
- Usage:
-T
- Print file system type
- Usage:
-h
- Human readable format
- Usage:
-i
- Display inode usage intead of block usage
mount
- mount a filesystem
- Example:
mount /dev/sdb1 /mnt
- mount my SD-Card (on dev/sdb1, you can check it by command sudo fdisk -l
)
- Ubuntu: Ubuntu will automatically mount you disk into the path
/media/
, check there.
umount
- umount a filesystem
- Example:
umount /mnt
- umount my SD-Card from /mnt
Processes
cron
- Function: Used to do automation work
- Record format: m h dom mon dow use command
- Format explanation
- m: minute, integer from 0 to 59
- h: hour, integer from 0 to 23
- dom: day of month, integer from 1 to 31
- mon: month, integer from 1 to 12
- dow: day of week, integer from 0 to 7
- command: command to excute
- Specific symbol you can use
- -: a range, example: 1-4, represent 1, 2, 3, 4
- ,: a list, example: 3, 4, 6, 8
- /: define a frequency, if you put / after /, it means it will jump integer in range. Example, 0-59/2, it will excute command every 2 minutes.
- #: code comment
- Pay attention
- there is no second in crontab
- if a task need to be excute by dispatch, you can add your crontab file into /etc/cron.d directory, all files in this dir must use same syntax as /etc/crontab did.
- Usage of cron
- start cron service, use command /sbin/service crond start, crond mean cron daemon process.
- allow and deny user to use crontab in /etc/cron.allow and /etc/cron.deny
- crontab -e: edit schedule use a custom editor
- crontab -r: delete current schedule
- crontab -l: list current schedule
- my crontab
- 1 0-9/3 * * * (/bin/sh /home/h/publishing/xuelianghan.github.com/generate.sh)
- 5 0-9/3 * * * (/bin/sh /home/h/publishing/xuelianghan.github.com/up.sh)
- 1 10-23/2 * * * (/bin/sh /home/h/publishing/xuelianghan.github.com/generate.sh)
- 5 10-23/2 * * * (/bin/sh /home/h/publishing/xuelianghan.github.com/up.sh)
Searching
Index
- find grep locate whatis whereis
- who
- note: need more practical practise
find
- search for file in a directory hierarchy
- Usage:
find {dir-name} -name {file-name}
locate
- find files by name
grep
(egrep, fgrep, rgrep
) - print a line_ mathcing a __pattern
whatis
- display manual page descriptions
- Example:
whatis gcc
- Result: gcc (1) - GNU project C and C++ compiler
whereis
- locate the binary, source, manual page files for a command
- Example:
whereis gcc
- Result: gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
who
- list users currently logged in
Text processing
- Index
- awk banner basename comm csplit cut dirname ed ex fmt fold head iconv join less more paste sed sort spell strings tail tr uniq vi wc xargs
awk
- awk is useful, but it has been in the shadow of perl from beginning, due to perl is capable to cross platform, and awk is not so compatible out of unix/linux plafform, but, awk is good at get some small things done.
- awk function
- length(), index(), split(,,)
- small practise
$ cat > awk.txt
testing the awk command
- print length of the first line
(wrong) $ awk
{ 1 = length($0; print i}
awk
(right) $ awk '{ i = length($0); print i }' awk.txt
(result) 23
- print the position of string "ing"
$ awk '{ i = index($0, "ing"); print i }' awk.txt
- split the text by space and print each word
$ awk BEGIN {i = 1} { n = split($0,a," "); while (i < = n) {print a[i]; i++;} }' awk.txt
Shell builtins
Others
diff
ls
- lsusb
- list all use devices information, I use it to check my mobile phone udev info when develop android apps.
lsof
list all filesystem UUID
- list directory tree -
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
(it works)
Utilities
cat /proc/self/maps, objdump -h /bin/cat