Here are some useful command line tips and tricks for Linux/Unix systems. Indispensable are commands to find certain processes or files which match a specific name or keyword:
$ ps ax | grep "tomcat" # returns all instances of tomcat runnning on your system $ find . -name *xml # find all XML files in the current directory $ grep -r keyword * # find all Files which match a certain keyword recursively
If you want to inspect log files, the following commands are useful. The grep command is useful to get all log file entries for a certain expression with a short description (-Ax means list x lines after the match) e.g. to list all logins, all registrations, or all exceptions of a certain kind
$ tail -f error.log # view live access to log file $ grep -A1 keyword *.log # find all lines around the match for a certain keyword, # i.e. all logins for the keyword="SessionsController#create"
Various commands are available to add and count line numbers..
$ ls | nl # Numerates files in a directory $ ls | wc -l # Count the number of files in a directory $ cat README | wc -l # Count the number of lines in a file $ nl -ba README # Show file content with line numbers
Some essential file system operations:
$ ls -lsrt # file list sorted by (reverse) timestamp. $ scp file.txt username@server:~ # copy file from local machine to remote server $ scp username@server:~/file.txt . # copy file from remote server to local machine