Skip to main content

20 Linux Commands for Listing Users, Folders, and Processes on Ubuntu and Red Hat

 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

  1. cat /etc/passwd
    Displays a list of all users on the system along with their user IDs, home directories, and shells.

  2. getent passwd
    Fetches user information from the system's databases, useful in environments with LDAP or NIS.

  3. who
    Shows all users currently logged in to the system.

  4. w
    Displays detailed information about logged-in users, including their active processes.

  5. users
    A simple command that lists the currently logged-in users.

  6. id [username]
    Displays user ID (UID), group ID (GID), and group memberships for a specific user.

  7. finger [username]
    Provides information about a user, including their real name, login time, and more. (May require installation: sudo apt install finger on Ubuntu, or sudo yum install finger on Red Hat).


2. Listing Folders and Files

  1. 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.

  2. tree
    Displays directories and their contents in a tree-like structure. (Install using sudo apt install tree or sudo yum install tree).

  3. find /path/to/search -type d
    Finds and lists all directories under a specified path.
    Example: find /home -type d.

  4. du -h --max-depth=1
    Shows the size of directories in the current location, useful for identifying large folders.

  5. df -h
    Displays disk usage for mounted file systems, including directories.

  6. stat [filename]
    Provides detailed information about a file or directory, such as size, permissions, and last modification time.

  7. lsblk
    Lists all block devices and their associated mount points, useful for identifying file systems.


3. Listing Processes

  1. ps aux
    Displays all running processes, including user information, CPU usage, memory usage, and more.

  2. top
    Provides a real-time view of running processes and system resource usage.

  3. htop
    An interactive process viewer similar to top but with more features. (Install using sudo apt install htop or sudo yum install htop).

  4. pidof [process_name]
    Returns the Process ID (PID) of a specified process.
    Example: pidof apache2.

  5. pgrep [process_name]
    Searches for processes based on their names and displays their PIDs.
    Example: pgrep sshd.

  6. kill -l
    Lists all available signals you can send to processes. Combine this with kill [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

Popular posts from this blog

Automating VLAN Creation on Cisco Devices with Ansible

  Automating VLAN Creation on Cisco Devices with Ansible Ansible is a powerful automation tool that simplifies network management tasks, including creating VLANs on Cisco devices. For beginners, this guide will walk you through automating VLAN creation step-by-step, from setting up Ansible to deploying VLAN configurations. What is a VLAN? A VLAN (Virtual Local Area Network) is a logical group of devices within a network that can communicate as if they were on the same physical network, regardless of their physical location. VLANs improve network efficiency and security by segmenting traffic. Why Use Ansible for VLAN Automation? Consistency: Avoid manual configuration errors. Efficiency: Configure multiple devices in seconds. Scalability: Manage large-scale networks easily. Flexibility: Supports various Cisco devices and integrates with other tools. Prerequisites Cisco Device Configuration: Ensure your Cisco devices support SSH and are configured to allow Ans...

30 Linux Commands You Should Know

Linux is a powerful operating system used by developers, system administrators, and tech enthusiasts worldwide. Whether you're new to Linux or brushing up on your skills, here are 30 essential commands every Linux user should know: Start Learning   Linux Fundamentals  For Free 1. ls Lists files and directories in the current directory. ls 2. cd Changes the current directory. cd /path/to/directory 3. pwd Prints the current working directory. pwd 4. touch Creates an empty file. touch filename 5. mkdir Creates a new directory. mkdir new_directory 6. rm Removes files or directories. rm filename Use rm -r for directories. 7. cp Copies files or directories. cp source destination 8. mv Moves or renames files and directories. mv oldname newname 9. cat Displays the contents of a file. cat filename 10. nano Opens a simple text editor. nano filename 11. vim A powerful text editor. vim filename 12. chmod Changes file permissions. chmod 755 filen...