Random Hints and Tips
From CafeWiki
An assortment of command and tips to do various interesting (and sometimes important) things on a linux box:
What CPU have I got?
$cat /proc/cpuinfo
How much memory?
$cat /proc/meminfo
More detailed CPU/system information?
$sudo lshw
What version of linux is this anyway (2 methods)?
$lsb_release –a $cat /etc/issue
Who are the users on the system?
$cat /etc/passwd
What groups are on the system?
$cat /etc/group
How is a user added? This can be tricky as there is an "adduser" command that works differently, in some cases, it might be even easier to just use the webmin interface if you have it installed.
$useradd username
How do I reboot the box from the CLI (2 methods)?
$sudo reboot $sudo shutdown -r 0
How to I (securely) copy a file from one server to another server? This works to send a file to another server as well, see this example. Switches are -p to preserve permissions and modification times, -r for recursive copying of a directory. Note that if you want to use scp in a script (to copy backup files to another server location, for example) the need for the password on the remote host will thwart you. This website describes the use of a ssh-keygen private/public key pair to use the capabilities of ssh to remove the need for the password.
$scp [-p][-r] [[user@]from-host:]source-file [[user@]to-host:][destination-file]
How do I find previous commands in the history file? See this site for more examples.
$<ctrl-r>
(reverse-i-search)`red': [search-string] {left or right arrow allows edits}
$history | grep [search-string]
How do I execute a specific command from the history? (Once the command number is known, e.g. from grepping the history)
$![cmd-number]
How do I capture a command line session, both commands and responses (Ref)?
$script filename $<enter commands as desired> ... $ctrl-d <to exit>
How do I do a screen shot in Windows running as a VM or in bootcamp on a Mac since there is no PrtScrn button on a Mac keyboard? Refer to this Apple support article.
On a MacBook: fn-shift-F11 for the whole screen
fn-shift-alt-F11 for the active window
From a Mac keyboard, this also seems to work: ctrl-shift-alt-F14 grabs the whole screen
I need to find a file and I know at least part of the filename.
find /path/to/search -name *partfilename* -type f
Note that the find command has lots of options including things like -delete which will delete the files that have been found or -mtime to find files based on modification time. So, how do I find all the database backup files (-name "*.sql") files (- type f) older than 60 days (-mtime +60) and delete (-delete) them?
find /path/to/backups/ -name "*.sql" -type f -mtime +60 -delete
I need to find a file in the current directory (or in a subdirectory) that contains a specific string of text:
find . | xargs grep text_string
