Monday, 3 January 2011

Aide Memoire - Some useful (to me) Linux commands

Want to know what files are open ?


Want to know what files are opened by a specific process ?

lsof -p <pid>

- as an example, I've identified that WebSphere Portal is running as process ID ( pid ) 7725 so I use lsof -p 7725 to see all the files opened by that process

Want to know how large a file is ?

ls -lh

Want to see a file listing in order of modification ?

ls -ltrc

- shows the most recently modified at the bottom of the list

Want to search a binary file ?

grep --text <pattern> <filename>


grep -a <pattern> <filename>

- this gets around the error Binary file /opt/IBM/WebSphere/AppServer/java/bin//java matches
- I needed this to search a couple of logs files that contained some binary characters

Want to see files by type e.g. executable ?

ls -lF <filename>

- for example, this adds an asterisk to the listing to mark executable files

Want to list files without typing ls -alF ?

ll <filename>

- this is a useful little alias, as defined in ~/.bashrc

Want to know more about a process ?

Using the above example of WebSphere Portal running as process ID (pid) 7725, there are a bunch of files under the directory /proc/7725/ including: -

cat /proc/7725/status - shows memory utilisation etc.
cat /proc/7725/limits - shows various ulimits including open files etc.

- the first one was useful in confirming that my addition of ulimits -f 40000 to /opt/IBM/WebSphere/wp_profile/bin/ had "taken" - this helped me overcome a "Too many open files" exception

No comments:

Docker and Node and macOS - Computer Said No

I'm using a Docker container that runs a NodeJS application to lint-check YAML files relating to my new best friend,  Tekton CD . This c...