Monday 3 January 2011

Aide Memoire - Some useful (to me) Linux commands

Want to know what files are open ?

lsof

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>

or

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/setupCmdLine.sh had "taken" - this helped me overcome a "Too many open files" exception

No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...