- 10 Linux commands to know the system
- 10 Linux commands to know the system
- 1. free – get free and used memory
- 2. hwinfo – probe for hardware
- 3. id – know yourself
- 4. lsblk – list block storage devices
- 5. lsb_release – Linux distribution information
- 6. lscpu – display info about the CPUs
- 7. lstopo – display hardware topology
- 8. lsusb – list usb devices
- lspci – list PCI devices
- 9. timedatectl – view current date and time zone
- 10. w – who is logged in
- Conclusion
- 10 basic Linux commands you need to know
- ls lists directory contents
- More Linux resources
10 Linux commands to know the system
10 Linux commands to know the system
Open the terminal application and then start typing these commands to know your Linux desktop or cloud server/VM.
1. free – get free and used memory
Are you running out of memory? Use the free command to show the total amount of free and used physical (RAM) and swap memory in the Linux system. It also displays the buffers and caches used by the kernel:
free
# human readable outputs
free -h
# use the cat command to find geeky details
cat /proc/meminfo
However, the free command will not give information about memory configurations, maximum supported memory by the Linux server, and Linux memory speed. Hence, we must use the dmidecode command:
sudo dmidecode -t memory
Want to determine the amount of video memory under Linux, try:
lspci | grep -i vga
glxinfo | egrep -i ‘device|memory’
See “Linux Find Out Video Card GPU Memory RAM Size Using Command Line” and “Linux Check Memory Usage Using the CLI and GUI” for more information.
2. hwinfo – probe for hardware
We can quickly probe for the hardware present in the Linux server or desktop:
# Find detailed info about the Linux box
hwinfo
# Show only a summary #
hwinfo —short
# View all disks #
hwinfo —disk
# Get an overview #
hwinfo —short —block
# Find a particular disk #
hwinfo —disk —only /dev/sda
hwinfo —disk —only /dev/sda
# Try 4 graphics card ports for monitor data #
hwprobe=bios.ddc.ports=4 hwinfo —monitor
# Limit info to specific devices #
hwinfo —short —cpu —disk —listmd —gfxcard —wlan —printer
Alternatively, you may find the lshw command and inxi command useful to display your Linux hardware information:
sudo lshw -short
inxi -Fxz
inxi is system information tool to get system configurations and hardware. It shows system hardware, CPU, drivers, Xorg, Desktop, Kernel, gcc version(s), Processes, RAM usage, and a wide variety of other useful information [Click to enlarge]
3. id – know yourself
Display Linux user and group information for the given USER name. If user name omitted show information for the current user:
id
See who is logged on your Linux server:
who
who am i
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
4. lsblk – list block storage devices
All Linux block devices give buffered access to hardware devices and allow reading and writing blocks as per configuration. Linux block device has names. For example, /dev/nvme0n1 for NVMe and /dev/sda for SCSI devices such as HDD/SSD. But you don’t have to remember them. You can list them easily using the following syntax:
lsblk
# list only #
lsblk -l
# filter out loop devices using the grep command #
lsblk -l | grep ‘^loop’
5. lsb_release – Linux distribution information
Want to get distribution-specific information such as, description of the currently installed distribution, release number and code name:
lsb_release -a
No LSB modules are available.
6. lscpu – display info about the CPUs
The lscpu command gathers and displays CPU architecture information in an easy-to-read format for humans including various CPU bugs:
lscpu
Cpu can be listed using the lshw command too:
sudo lshw -C cpu
7. lstopo – display hardware topology
Want to see the topology of the Linux server or desktop? Try:
lstopo
lstopo-no-graphics
You will see information about:
- NUMA memory nodes
- shared caches
- CPU packages
- Processor cores
- processor “threads” and more
8. lsusb – list usb devices
We all use USB devices, such as external hard drives and keyboards. Run the NA command for displaying information about USB buses in the Linux system and the devices connected to them.
lsusb
# Want a graphical summary of USB devices connected to the system? #
sudo usbview
usbview provides a graphical summary of USB devices connected to the system. Detailed information may be displayed by selecting individual devices in the tree display
lspci – list PCI devices
We use the lspci command for displaying information about PCI buses in the system and devices connected to them:
lspci
9. timedatectl – view current date and time zone
Typically we use the date command to set or get date/time information on the CLI:
date
However, modern Linux distro use the timedatectl command to query and change the system clock and its settings, and enable or disable time synchronization services (NTPD and co):
timedatectl
10. w – who is logged in
Run the w command on Linux to see information about the Linux users currently on the machine, and their processes:
Conclusion
And this concluded our ten Linux commands to know the system to increase your productivity quickly to solve problems. Let me know about your favorite tool in the comment section below.
Источник
10 basic Linux commands you need to know
Whether you’re a Windows system administrator looking to expand your skills into Linux, a fresh convert to Linux, or someone who’s looking to find a job in IT, this introduction to some common Linux commands is for you. These 10 commands are the ones that Linux system administrators use frequently—in fact, they use at least eight of them on a daily basis. And no matter how long you use Linux, you’ll always use these commands. Some of you MS-DOS users will recognize a few of these and, not surprisingly, they have the same function in both operating systems.
ls lists directory contents
More Linux resources
The list ( ls ) command is equivalent to the DOS DIR command, in that it lists files and directories. If you simply type ls at a prompt ( $ ), you’ll see all non-hidden files in your current directory, which is your home directory when you first log into a Linux system. The ls command won’t show you much in your home directory on a new system, so let’s explore a directory that contains a lot of files and directories: /etc . The /etc (et-see) directory is where a Linux system’s configuration files live.
A large number of files (over 200) appear on your screen. You’ve successfully listed the contents of the /etc directory, but you can actually list files in several different ways. Above, I mentioned non-hidden files. In your home directory, where you are now, you probably have hidden files. Hidden files in Linux begin with a period ( . ). For example, you likely have a .bash_profile file there. To see it, use the following ls command.
You now see several files beginning with a period. The -a switch—or option, as it’s called—shows you all files, even hidden ones.
man displays manual pages
Linux has an extensive set of online documentation for your reference. They’re referred to as manual pages, as in read the manual. The abbreviated command for referencing this documentation is, man and a screen-full of information appears before you.
It’s easy to navigate man pages. Use the Enter key to advance one line at a time, the ‘ b ‘ key to go back, the Space bar to advance a full-screen page, and the ‘ q ‘ key to exit the man page. As an example, look at the man page for the ls command.
cat concatenates files
The cat command is important as a basic command because it serves two very important functions: concatenating (merging) files (as the name suggests) and printing the contents of a file to the screen. Printing the contents of files is by far the more frequent use of this command. If you want to see a file’s contents, use the following format:
For example, you might type the following to display the contents of the system’s passwd file on the screen:
To use cat for its file concatenation powers, the general form of the command is:
$ cat file1 file2 > file1file2
For example, to redirect the contents of grocerylist.txt and todo_list.txt into the Saturday.txt file:
$ cat grocerylist.txt todo_list.txt > Saturday.txt
You can concatenate as many files as you want into a single file using cat .
touch changes file timestamps
The touch command is another one that serves a dual purpose. Its designated purpose is to update the timestamps on files. If you list the contents of a directory in long format with:
The command’s output displays the permissions, ownership, size, created or last accessed date/time, and the filename:
-rw-rw-r—. 1 khess khess 175 Jul 23 19:19 all.txt
-rw-rw-r—. 1 khess khess 61 Jul 23 19:17 new.txt
-rw-rw-r—. 1 khess khess 114 Jul 23 19:09 students.txt
Use touch to update the last accessed timestamp:
-rw-rw-r—. 1 khess khess 175 Jul 23 19:19 all.txt
-rw-rw-r—. 1 khess khess 61 Jul 26 11:28 new.txt
-rw-rw-r—. 1 khess khess 114 Jul 23 19:09 students.txt
Using touch to update last accessed time is actually an infrequent use of this command. The common use for touch is to create an empty file as a placeholder. Some programs require that a file exists to operate correctly, and this is one method of kickstarting such a process. Otherwise, this use offers a quick way to create a file without opening a text editor and then saving an empty file:
-rw-rw-r—. 1 khess khess 175 Jul 23 19:19 all.txt
-rw-rw-r—. 1 khess khess 61 Jul 26 11:28 new.txt
-rw-rw-r—. 1 khess khess 114 Jul 23 19:09 students.txt
-rw-rw-r—. 1 khess khess 0 Jul 26 11:53 today.txt
You have created a new empty file, today.txt .
pwd prints the working directory
The pwd command is your Linux system’s compass, in that it tells you where you are. It has no other function than supplying that bit of information to you. Try the following, and you will see that you’re in your home directory, which is shown in the format /home/ :
$ pwd
/home/khess
If you get lost, or just wonder where you are in the filesystem, this is the command that will tell you. Linux users use it frequently before changing or removing files to be sure of their current location.
The pwd command always displays the full path to your location, even if you’re multiple directories deep from the root ( / ) directory, which is why I see /home/khess rather than khess or /khess .
cd changes directory
Very closely related to the pwd command is the cd command. Changing directories is a frequent activity on a Linux system. As stated before, when you first log in, you’re placed into your home directory. Every user on a Linux system has a home directory. Regular user accounts have personal directories under the /home directory. Your home directory is under /home/ . To view all user’s home directories, cd to the /home directory.
What you see here depends on your system. If you are the only user on a personal system, you will only see your home directory. Production systems might have hundreds of user accounts on them. The quick way to return to your home directory, no matter where you are on the system, is to type cd with no arguments or directory paths:
So, if you ever get «lost» on the system and need to reset your bearings, type cd and you’ll be placed safely into your home directory. You can cd to almost any directory on the system by supplying its full path after the cd command:
To change directory to the one above your current directory, use the double period (dot) argument:
Now you are in the /usr directory. Remember that you can «prove» your location to yourself by issuing the pwd command:
There are times when you don’t need to cd to a particular directory. You can read a file from your current location if you supply the full path to the file you’re interested in viewing. For example, you don’t need to cd to the /usr/bin directory to issue the pwd command. You issue it from your current location because it is in your path.
The path is a more advanced topic for another article, but just be aware that you don’t need to cd to do everything. The time to cd is when you will be working in a specific directory for some reason. Otherwise, you can do what you need to do from your home directory. You’ll find out why changing directories can be a bad thing in the next section.
rm removes files and directories
The rm command removes (deletes) files and directories. One of the quirks of Linux that you’ll find different from DOS/Windows is that it isn’t chatty, which means that when you remove a file or directory, you won’t (by default) receive a message such as, «Are you sure?» It just isn’t the Linux way. There is a recommended workaround for that behavior that I’ll show you later in this section.
For now, let’s remove the today.txt file that you created earlier with the touch command:
Did you notice that you didn’t receive any questions or prompts? Linux assumes you know what you want to do before you hit the Enter key. That’s a little disconcerting, isn’t it? Ask Linux system administrators if any files have ever gone missing during one of their sessions. I’ll put money on an affirmative response and I’m not a gambler. You can work around this non-interactive behavior of certain commands by placing a -i switch (option) after the command. Try the following example:
$ rm -i newfile.txt
rm: remove regular empty file ‘newfile.txt’?
The -i makes rm interactive. Answer with a y and the file goes away. Answer with an n and you keep the file. To be safe, you can always use the -i switch with rm . There’s no harm or shame in it and you’ll be glad you did at some point in the future.
cp copies files and directories
Copying files and directories is a very common task for Linux system administrators. There’s no great secret to its usage and you simply issue the copy ( cp ) command, the file or directory source, and the destination. To copy a file, file.txt , to the /opt/files directory, use:
$ cp file.txt /opt/files
To copy an entire directory and all its contents, including subdirectories, use the -R (Recurse) option. Copy the data directory in your home directory to /opt/files . You can use either the -r or -R to recurse copy files:
$ cp -R data /opt/files
The cp command is rare in that both the upper- and the lowercase options for an action are the same. Of course, you can use wildcards when copying files to filter them with patterns:
$ cp *.txt /opt/files
mkdir makes directories
If you’re an organized person, you’ll want to create directories to satisfy your need to properly arrange your files and data into separate compartments (directories). It’s easy to create directories. Issue the mkdir command followed by the directory name you wish to create:
If you’re even more organized and you’ve done some planning, you can create a whole hierarchy of directories with one command. You want to create a data directory that includes subdirectories for documents, forms, tests, and outgoing. Why issue multiple commands when you can do it all at once:
$ mkdir -p data/documents/forms/tests/outgoing
The -p option tells the system that you are creating a parent directory and subdirectories. Check your work using the ls command. You can also create multiple directories at the same level all at once.
$ mkdir docs spreadsheets email old
Use the ls command to be sure the mkdir command did what you wanted it to do.
ps lists the current running processes
The last of the 10 basic Linux commands you need to know is ps . This command shows you currently running processes. If you issue the ps command, you will only see your own processes:
$ ps
PID TTY TIME CMD
7505 pts/0 00:00:00 bash
18119 pts/0 00:00:00 ps
If you’re not running anything, then this output is not very interesting. It’s far more interesting to see what’s going on system-wide. You can do this by adding some options to ps . The most valuable options are -e and -f , for every (all) and full format, respectively. To get the most information from the ps command, combine the two options into the following command. I’ve included the first few lines from the output of ps -ef from my system for you:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jul23 ? 00:00:25 /usr/lib/systemd/systemd —system —deserialize 20
root 2 0 0 Jul23 ? 00:00:00 [kthreadd]
root 3 2 0 Jul23 ? 00:00:00 [rcu_gp]
root 4 2 0 Jul23 ? 00:00:00 [rcu_par_gp]
root 6 2 0 Jul23 ? 00:00:00 [kworker/0:0H-kblockd]
root 8 2 0 Jul23 ? 00:00:00 [mm_percpu_wq]
The fields are simple to understand and useful when troubleshooting performance problems:
Field | Description |
---|---|
C | CPU Usage. |
CMD | The command or process name with path. |
PID | Process ID. |
PPID | Parent Process ID: The parent process is the one that spawned the process. |
STIME | Start Time for the process. |
TIME | CPU Time for the process. |
TTY | The user terminal that spawned the process. System process will show a ?. |
UID | User ID of the process owner. |
There are other options you can use with the ps command, and it seems everyone has a preference, but the two most popular are: ps -ef and ps aux . They both provide you with a lot of process information.
There you have the 10 basic Linux commands you need to know. There isn’t one command that’s more important than any other. They’re all important and they’re all useful. I chose these because they are the 10 commands that everyone regularly uses whether you’re a fresh newbie or an old salty system administrator from the dark days before Linux.
If you’re interested in how DOS and Linux commands compare, check out this: Comparison of Common DOS and Linux Commands.
[Want to try out Red Hat Enterprise Linux? Download it now for free.]
Источник