Site icon GIXtools

Linux fundamentals: Viewing files, commands, processes and systems

Linux provides a useful array of commands for managing file permissions, getting information on commands, displaying running processes and displaying details on the system itself.

File permissions

chmod: change file permissions

One command that’s important when working with files is the chmod command. It allows you to set file permissions, determining who has read, write and execute permissions. The chmod command will, for example, allow you to make a file executable, which is important when you prepare a script to automate some routine task. Using a command such as chmod 755 would make a file readable and executable by anyone who has access to it. This command is generally only used for a script that will be sitting in a location that other users have access to. To change settings so that you can run a script that you’ve prepared, use a command like chmod 700 myscript (replacing “myscript” with the name of your script). This will give you read, write and execute permission to the file while not providing privileges to other users.

In general, creating a script requires that you use a text editor such as vi. The first line in the example below, however, uses the echo command to create a one-line file called “myscript”. The chmod command shown in the following line makes it executable. When the script is run, the username shown will reflect whoever is running it.

$ echo "echo Hello, $USER" > myscript
$ chmod 700 myscript
$ myscript
Hello, jdoe

Details on commands

whatis: display one-line manual page descriptions

whereis: locate the binary, source, and manual page files for a command

man: display a command’s man page

To get information on commands, you can use the whatis command (e.g., whatis chmod) to give a one-line description of what the command is used for, whereis (e.g., whereis echo) to display the location of the executable, and man to display the command’s man page – a description of the command and its options.

Details on the system

uname: display system information (e.g., distribution and release)

The uname command will provide a line of information on the system itself – the Linux distribution and release along with the current date and time – but only if you add the -a option. Without this, it will likely just respond with “Linux”.

ifconfig: display or configure a network interface

The ifconfig command will provide information on the system’s network interfaces – the interface that the system uses to communicate with other systems and the loopback interface which it uses to communicate with itself in a similar manner to how it communicates with other systems.

Comparing files

diff: compare files line by line

cmp: compare files byte by byte

comm: compare sorted files line by line

Linux provides several commands for comparing text files. If you run a command such as diff file1 file2 you’ll see the lines that are only in the first file preceded by signs. If you use the cmp command, you’ll just see where the differences in the files start (e.g, byte 25, line 4). No output means the files are identical. The comm command displays its output in an indented format – the leftmost column containing the common lines, the next displaying the lines in the first file only, and the last showing the lines in the second file only. The files’ contents should be in sorted order.

Viewing running processes

ps: display running processes

You can view processes on the system using the ps command. Without arguments, the output will only display the processes you are running. Use ps -ef or ps -aux to view all of the processes running on the system (i.e., as many as will fit into your terminal window).

top: display list of running processes in activity order

The top command will give you an idea how busy the system is overall. It will display things such as load averages, memory usage, the number of processes running and CPU usage in the first lines. This will be followed by a list of running processes showing those using the most system resources first five lines and then fill your terminal window with as many other processes as fit in your terminal window – all in system usage order. The display will update itself every few seconds or so.

Wrap-up

To learn more about Linux commands, you might want to get your hands on a Linux command cheat sheet. And if you’re using the bash shell, a bash cheat sheet can help you start writing scripts that allow you to automate routine tasks. Here are some options:

Source:: Network World

Exit mobile version