Linux Commands and System Administration Essentials
1. Viewing Directories
Use the following command to view directories:
find -type d
(finds all directories)ls -l
(lists files and directories in long format)
2. Folders Storing System Files
The following folders store system files:
/
(root directory)/dev
(device files)
3. Controlling Processes: Foreground (FG) and Background (BG)
In Linux, you can run multiple tasks simultaneously. To run a program in the background, add an ampersand (&) to the end of the command line.
Example:
# cp -r /usr/src/linux /tmp &
When the program finishes, the system will display a message:
[Done] cp -r /usr/src/linux /tmp
To move a background process to the foreground, use the fg
command.
3.1. Running Commands in Background and Using jobs
, fg
, and bg
To run a command in the background, use the & operator at the end of the command.
Example:
[cfm@salt]$ firefox &
[1] 23710
[cfm@salt]$
To view running background processes, use the jobs
command.
Example:
[cfm@salt]$ jobs
[1]+ Running firefox &
[cfm@salt]$
To bring a background process to the foreground, use the fg
command with the job number.
Example:
[cfm@salt]$ fg 1
firefox
To stop a foreground process and move it to the background, press Ctrl+Z and then use the bg
command.
Example:
[1]+ Stopped firefox
[cfm@salt]$ bg 1
[1]+ firefox &
[cfm@salt]$
3.2. Important Note about Background Processes
If a background process requires user interaction through the console, it will remain stalled.
4. Deleting a Folder and its Contents
Use the rm -r
command to delete a folder and its contents.
5. Background (BG) and Foreground (FG) Process Control
Linux allows running multiple tasks concurrently. To run a program in the background, append an ampersand (&) to the command.
6. nice
and renice
Commands
These commands allow you to launch a process with a specific priority (nice
) and change the priority of an existing process (renice
).
6.1. nice
Command
- Starts a program with an altered priority.
- Nice range is from +19 (very nice/low priority) to -20 (not very nice/high priority).
- The default nice value is 10.
Examples:
$ nice -10 long-running-command &
$ nice -n 10 long-running-command &
$ nice -15 important-command &
$ nice -n -15 important-command &
6.2. renice
Command
- Changes the nice level of an existing process.
- Users cannot increase the nice level (lower the priority) of a process without appropriate permissions.
Examples:
$ renice 20 2984
$ renice -15 3598
$ renice 15 -u miguel
7. Deleting a Directory
Use the rm
command to delete a directory.
Examples:
$ rm filename
$ rm directory_name
$ rm -r directory_name
8. Linux File Systems
Common Linux file systems include:
- ext3
- ext2
- swap
9. Creating a Hard Link
Use the ln
command to create a hard link.
Example:
$ ln original_file hard_link
10. Files Containing User and Password Information
/etc/passwd
(stores user information)/etc/shadow
(stores password information)
11. Changing Process Priority
Use the nice
and renice
commands to change process priority.
11.1. renice
Command Details
The renice
command alters the priority of running processes.
Syntax:
renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]
Options:
-g
: Interprets parameters as process group IDs.-u
: Interprets parameters as usernames.-p
: Interprets parameters as process IDs (default).
Examples:
renice +15 785
renice +20 -u fred
12. UMASK
UMASK is used to determine the default file permissions. For example, if you want default permissions of 644, the umask would be 022 (666 – 022 = 644).
13. Viewing Processes
Use the ps aux
command to view all running processes, including their memory and CPU usage.
14. Generating SSH Keys
To generate SSH keys, use the following command:
ssh-keygen -t rsa
This command creates a public/private RSA key pair. You will be prompted to enter a filename for the private key (default is /home/user/.ssh/id_rsa
) and optionally a passphrase.
15. Switching Between Consoles
Use Ctrl+Alt+F1 through Ctrl+Alt+F6 to switch between virtual consoles.
16. Privileged Ports
Ports below 1024 are considered privileged ports. Some common privileged ports include:
- SSH: 22
- Telnet: 23
- HTTPS: 443
- NetBIOS: 137
- CUPS (printing): 631
There are a total of 65535 ports available.