I saw a post on Slashdot about “Stupid Unix Tricks” that talked about common things you take for granted in Unix or just flat out forget are there. With my RHCE exam coming up, it got me thinking about how many aliases and shell scripts I’ve written for myself that I use daily that won’t be there on the exam. Between those and my preference for emacs over vim, I need to reacquaint myself with a vanilla Red Hat Enterprise Linux installation so I’m not constantly stumbling over my habits on the exam.
Below are a list of either my favorites that I use constantly (some aren’t mind blowing but just a look into my habits) or ones from the Slashdot article that seemed particularly useful or cool.
- Colored ls – If your shell doesn’t include this by default, this alias will use color for all of your ls calls.
1
| alias ls='ls --color=auto' |
jardump – For each JAR file found in the current directory or any child directories, output its contents to a file named jardump.txt. Very useful when using maven as it can be run in the maven repository directory to get a full listing of all classes in all JARs in the repository.
1
| find . -name '*.jar' -exec unzip -l {} \; > jardump.txt |
- Change to a real directory from a symlink.
- Commands can be executed on a remote machine through SSH without actually logging in. This is especially useful if you use key based login instead of passwords.
1
| ssh [user]@[server] [command] |
For example:
1
| ssh professorjay@novasurv.com ls /var/www |
- Human readable listing of disk space.
- List the contents of a zip file without actually unzipping it (tip: pipe it to less to scroll the contents if they are long).
- Extract a file in a zip to standard output rather than writing it to the disk, letting you read a file without unzipping the zip file. Again, you can pipe this to less to scroll the contents of the file.
1
| unzip -p [zip file] [full path to file in the zip] |
For example:
1
| unzip -p dom4j.jar META-INF/MANIFEST.MF | less |
- A coworker introduced me to
tee, which reads from standard input and writes to standard output and to a file. I use it when building so I can see the build messages in my shell like normal but also have a copy stored somewhere. The easiest way to explain it is with an example:
1
| make | tee /tmp/make-results.txt |
- Add a new supplementary group to a user without having to respecify all of the user’s existing supplementary groups.
1
| usermod -aG [newgroup] [user] |