Linux Commands
Hey, Linux has a pretty steep learning curve... why memorize, just use this handy reference.
Note: Many more complex ones have their own Scribbles. Generally linked to this one.
-
Find version of Glib, or any RPM: rpm -q glibc
-
Another (actually the precursor discussion thread) to search and replace: http://www.experts-exchange.com/Operating_Systems/Linux/Q_10515858.html#1
-
The 'bg' command can start backgroud processes again.
-
You can put multiple commands in a single line, just separate them with a semi-colon (;)
-
A good reference from O'Reilly: http://www.oreillynet.com/linux/cmd/
-
A Sysadmin's Unixersal Translator (ROSETTA STONE): http://bhami.com/rosetta.html.
-
Another good online book: http://www.icon.co.za/~psheer/book/rute.html.gz
-
List files modified in 2 days: find -mtime -2
-
Start a command with an "&" at the end of the line to launch it into the background.
-
A good sample page about cron and the time settings for it. http://www.wundermoosen.com/TMAHelp/pgs/TMACron.htm
-
Clear the screen (like CLS in dos) with "clear"
-
Good shell scripting guide: http://freeos.com/guides/lsst/
-
Change an IP address (RedHat): edit the ifconfig files in /etc/sysconfig/network-scripts/
-
Folder Size: List the size of a directory with "du" - e.g. "du -sh /tmp/my_folder" to get the total disk space used by a directory in human usable terms, e.g. 41Mb.
-
List files changed in the last x (5) days, recurse y (7) folders deep: find . -maxdepth 7 -mtime -5
-
Stop needing to type sudo all the type (Ubuntu!): sudo -s
-
Force fsck check at next boot: shutdown -rF now -- careful, this may not be completely automatic, you may need console access.
-
Recursive Examples:
-
Change permissions to files - from WordPress - find /home/x/public_html/ -type f -exec chmod 644 {} \;
-
-
From http://kerneltrap.org/node/view/1735:
-
find include -name \'*.h\' | xargs egrep \'static.*inline\' | wc -l
6288
That's 6,288 chances for you to #include GPL code and end upwith executable derived from it in *your* .o file, not the kernel\'s.
I think this command finds all files with *.h (C header files), then runs egrep on each one, and counts the number of times "static.*inline" is used in total.
-
List block devices (Linux Mint): lsblk -a
-
chown -R [owner]:[group] [file] - recursive change ownership of files.
-
-
-
atq - schedule a task for later.
-
bc - basic calculator
-
-
-
Related to troubleshooting a randomly open port in Linux:
-
-
fuser, rpcinfo, netstat
-
-
http://seclists.org/basics/2005/Oct/692
-
symlink
-
ln -s /path/to/file /path/to/symlink
User and Group Stuff
-
groups - lists groups the current user (or specific user, if spec'd) is in
-
cat /etc/group - list groups
-
cat /etc/passwd - list users and their group (?)
-
"there is a difference between the primary and supplementary groups. The primary group is the main one shown in /etc/passwd, that a user is in upon login. For a user to be in a supplementary group, their user name is added to the group entry in /etc/group. If you use id -a , it will show the primary and the supplementary groups. The supplementary groups give access to resources, but any new files are created with primary group." - https://serverfault.com/questions/605812/etc-passwd-shows-user-in-a-group-but-etc-group-does-not
-
tar
-
de-tar: tar -xf [filename.tar]
-
decompress gz: gzip -d [filename.gz]
-
Uncompress a ".tgz" file: tar -zxopf foo.tgz
-
ls (List)
-
Count Files in a folder (first is a number, second is the letter L): ls -1 | wc -l
-
-
-
tags: countfiles, listfiles, linux,
Networking
-
List network connections: cat /proc/net/ip_conntrack | grep 10.0.0.119
-
Get current gateway - netstat -nr
-
Cron
-
List all user's cron jobs - http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users -
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done\
Email
-
Handy one liner to send a file by email - echo | mutt -a /tmp/find-xargs.txt user@example.com
Auditing
-
List user logins: last | more (it's sorted from most recent to oldest)
tags: linux, commands, reference, cheatsheet