Unit Tricks and Tips

alias l='ls -AFC'

-A all files except . and .. -F add * to the end of executables, / to dirs, and @ to symlinks -C multi-column output

By the way, if you are an old time Unix geek annoyed by how ls now does a case-insensitive sort on filenames who wants the old behaviour back, add

export LANG=C

to your .bashrc.

alias ll='ls -la'

alias lll='ls -laL'

-l long format listing -a all files (including . and ..) -L follow symlinks, and list on the underlying file instead of the link

alias lr='ls -ltra'

-t sort by last modified time on files -r reverse the sort order, so that newest come last

ls -li

-i list inodes

less -MQseai

-M like more, only more so -Q quiet (no terminal bells, ever) -s squeeze multiple blank lines into one -a start next search on next page -i ignore case in searches

g go to line 1 G go to end of file N next file P prev file

m[a-z] mark the file '[a-z] return to mark F follow

export LESS=MQseai

LESSOPEN

alias man='man -a'

-a display ALL matching man pages

apropos (or man -k)

man pages whose summary matches the input

find

-name \*.html finds files that end in .html -iname \*.html as -name, but ignore case -follow follow symlinks -xdev don't cross filesystem boundaries -empty zero-length files and empty directories -newer filename find entries that are newer than filename -perm mode, -mode, +mode file permissions are exactly, all, or any of the bits in mode

Learn to think about file permissions in octal.

-type <char> only look at <d>irectories, <f>iles, <l>inks, and so on -print print matching names -print0 print matching names delimited by \0

Read the man page for find. Play with it. It will pay off.

xargs <cmd> <cmd-args>

Take lines from stdin, and comvert them into command args for cmd.

-0 use \0 as input separator, instead of \n

find and xargs are made for each other.

cpio -pdumv

copy entire directory trees, preserving everything

find and cpio are also made for each other

revmv, revln, revcp – shell scripts to use with find and xargs

symlinks versus hard links

symlinks pros – can cross filesystems cons – can have the rug pulled out from under them

hard links pros – can't have the rug pulled out from under them cons == can't cross filesystems

df, df -i

display free space, or free inodes

-h human readable -k kilobytes -m megabytes

du

display usage

-s summarise -c total -x don't cross filesystems -h human readable -k kilobytes -m megabytes

sort

sort files

-b skip leading blanks -n sort numerically -k<n> sort on field n -r reverse the sort order -u uniq lines only

Prefer to sort things so that the interesting bits come at the end.

uniq

get unique entries in a file

-c count occurrences -d duplicated lines only -u unique lines only

cut

cut the lines of a file into fields

-c<n>{-<n>} columns -f<n>{-<n>} fields -d<c> delimiter

paste

paste lines from several input files together

agrep

grep files with multi-line records

-d<delim> record delimiter

lsof

list open files and network connections (run as root)

-c<command> list only <command>

ifconfig

show the network config for a box

netstat

show the network status

-r show the routing table -g show multicast group membership

iostat vmstat sar

Show the disk i/o, vm activity, and system activity report

Specify a delay interval and a repeat count if desired

pstree

print process table as a tree

basename

get the basename of a file

dirname

get the directory name of a file

touch && >

set the last modified time to now. touch will also create the file if it does not exist. > will zero a file, or create it if it does not exist.

xxd

hex dump a file

objdump

dump an object file

-x dump all sections –demangle turn C++ mangled names back to human readable names

ldd

list dynamic object dependencies

namei realpath

find the real file

time

time a command

tee

split the pipe. send stdin to both stdout, and to a file.

-a append to a file

yes

repeatedly output the same string

column

print stdin in multicolumn format

tput clear

clear the screen

diff3

diff three files (e.g. diff3 mine original yours)

tr <string1> <string2>

translate characters in string1 to characters in string2

-s squeeze multiple occurrences together -c complement the first string -d delete characters in string1

sum && md5sum

compute a simple checksum, or an md5checksum

cal

print a calendar

dc && bc

two quick and simple calculators

tail && head

print the last/first -N lines of a file

tail -f follows a file waiting for new data

seq

output a sequence of numbers

hostname, uname, /etc/redhat-release

what is the hostname of the box, the unix name, and the redhat release

nice && renice

run a command at a lower priority, or change a running command's priority

file

identify what kind of file this is

uptime

how long has the system been up, and what is the load average

screen

start or reconnect to virtual screens

kill && killall

send a signal to running processes

-HUP send a hangup -KILL send a KILL (-9) to a process

stat

print stats on an inode

strace

trace all system calls from a running process

comm

compare two files, and produce three columns: uniq to file1, uniq to file2, and comm-on to both

ipcs

interprocess communication statistics

-l show limits

/proc

/proc/cpuinfo
/proc/meminfo
/proc/swaps
/proc/<pid>
unixtricksandtips.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0