Linux provides a variety of commands to retrieve information about system users, directories, and processes. This article presents 20 essential Linux commands for listing and managing users, folders, and processes, applicable to both Ubuntu and Red Hat systems.
1. Listing Users
-
cat /etc/passwd
Displays a list of all users on the system along with their user IDs, home directories, and shells. -
getent passwd
Fetches user information from the system's databases, useful in environments with LDAP or NIS. -
who
Shows all users currently logged in to the system. -
w
Displays detailed information about logged-in users, including their active processes. -
users
A simple command that lists the currently logged-in users. -
id [username]
Displays user ID (UID), group ID (GID), and group memberships for a specific user. -
finger [username]
Provides information about a user, including their real name, login time, and more. (May require installation:sudo apt install fingeron Ubuntu, orsudo yum install fingeron Red Hat).
2. Listing Folders and Files
-
ls
Lists files and directories in the current folder. Add options like-l(long format) and-a(hidden files) for more details.
Example:ls -la. -
tree
Displays directories and their contents in a tree-like structure. (Install usingsudo apt install treeorsudo yum install tree). -
find /path/to/search -type d
Finds and lists all directories under a specified path.
Example:find /home -type d. -
du -h --max-depth=1
Shows the size of directories in the current location, useful for identifying large folders. -
df -h
Displays disk usage for mounted file systems, including directories. -
stat [filename]
Provides detailed information about a file or directory, such as size, permissions, and last modification time. -
lsblk
Lists all block devices and their associated mount points, useful for identifying file systems.
3. Listing Processes
-
ps aux
Displays all running processes, including user information, CPU usage, memory usage, and more. -
top
Provides a real-time view of running processes and system resource usage. -
htop
An interactive process viewer similar totopbut with more features. (Install usingsudo apt install htoporsudo yum install htop). -
pidof [process_name]
Returns the Process ID (PID) of a specified process.
Example:pidof apache2. -
pgrep [process_name]
Searches for processes based on their names and displays their PIDs.
Example:pgrep sshd. -
kill -l
Lists all available signals you can send to processes. Combine this withkill [PID]to terminate or manage processes.
Examples for Common Use Cases
List All System Users
cat /etc/passwd | cut -d: -f1
List Active Processes for a User
ps -u [username]
List Large Files in a Directory
find /path/to/search -type f -size +100M
Find the Process Listening on a Specific Port
netstat -tulnp | grep [port_number]
Conclusion
These commands offer powerful ways to manage and monitor your Linux system. Whether you're an administrator or a curious user, mastering them will significantly enhance your Linux skills. Ubuntu and Red Hat both support these commands, ensuring versatility across distributions.
Do you have a favorite Linux command? Share it below!

Comments