• Welcome to Peterborough Linux User Group (Canada) Forum.
 

Favorite CLI commands

Started by Jason, September 06, 2021, 02:22:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jason

I knew most of you use the CLI (command-line interface), otherwise known as the terminal, on at least a semi-regular basis, right? Tell me I'm right. :D If I'm already named something, feel free to mention it anyway. I'm thinking we might learn a few new commands or just that the capability is there.

Anyway, thought it might be interesting to share what terminal commands we use the most. Some of these I use on the desktop, some on the server (PLUG server usually).

$ sudo apt update
$ sudo apt full-upgrade


Linux Lite handles updates fairly quickly but doing it in the terminal still feels faster. And have to use this for the server; no graphical environment.

$ df -h
- lists free space (df = disk free) as well as capacity and used space on your partitions including virtual and loopback ones
- the -h is for showing it in human form, so instead of 123456 bytes, you get 123 KB, etc.

$ kill <PID>
$ kill -9 <PID>

- kills a process (PID=Process ID) - you can do this graphically, too, but it's easier to do it this way if you need superuser privileges
- kill by itself is a graceful shutdown while -9 means to kill with extreme prejudice - forced to shut down no matter what

- to find that PID, you will need to use another command such as...
$ ps -e | grep <progam/process name>
- ps by itself only gives the processes running owned by the current user IN the terminal
- using -e shows all commands by the current user and I pipe that output to grep with a program name because there are a LOT of processes running

$ less <filename>
- good for looking at a file showing one screenful at a time; hitting any key goes to the next screen
- also good for piping output of another command to it

$ nano <filename>
- good for editing a file

$ free -h
- shows free, used and shared memory as well as used swap
- the -h does the same thing as with the df command

$ htop
- better than top - shows processes running, one program can spawn multiple processes

$ man <program>
- gives in-depth info about a command-line program and/or configuration file
- can use -h (sometimes --help) to get usage info and a list of options possibly with basic info about what they do

$ file <filename>
- tells you the format of a file, e.g. ASCII, and possibly lots of other info
- good for knowing what the heck something is and just kind of cool

$ which <program_name>
- tells you where a program is located; could be multiple locations

Obviously, I also use ls, mdkir, mv, rm, rmdir, etc. For most desktop users, you might not need the terminal at all but I think every Linux user should know a few, if only to fix things when your GUI doesn't work.
* Zorin OS 17.1 Core and Windows 11 Pro on a Dell Precision 3630 Tower with an
i5-8600 3.1 GHz 6-core processor, dual 22" displays, 16 GB of RAM, 512 GB Nvme and a Geforce 1060 6 GB card
* Motorola Edge (2022) phone with Android 13

fox

Several of mine overlap with yours, Jason, but one missing that I use a lot is
uname -r

... to tell me what kernel I'm running.

ls
cd <directory I want to change to>
rm -R <folder I want to delete>
Ubuntu 24.10 on 2019 5k iMac
Ubuntu 24.04 on Dell XPS 13

Jason

I actually didn't think about using '-r' with rm. I've used 'rm -rf' plenty of times. Dangerous commands!

Whenever I'm going to erase a set of files using a wildcard, I always do 'ls' with the parameter I intend to use in 'rm -rf' so I don't screw something up. Linux will quite happily erase your entire file tree if you have superuser permission and run... for a while. For example, before running:

$ rm -rf file*

I run:

$ ls file*

Sometimes you think a wildcard will just match certain files and it matches a lot more!

I use uname -r, too. And that reminded me of another one:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal


Some distros, I'm looking at you Fedora, don't seem to come with this tool. But it's easy enough to get.
* Zorin OS 17.1 Core and Windows 11 Pro on a Dell Precision 3630 Tower with an
i5-8600 3.1 GHz 6-core processor, dual 22" displays, 16 GB of RAM, 512 GB Nvme and a Geforce 1060 6 GB card
* Motorola Edge (2022) phone with Android 13

buster

"I knew most of you use the CLI (command-line interface), otherwise known as the terminal, on at least a semi-regular basis, right? Tell me I'm right. :D "

In Windows or in Linux I use the command line only when necessary. There is usually a method without command line. I read again today a comment in a magazine that Linux should never be recommended to anyone unless they are technically competent to use 'text commands'. This is so much horseshit.

Linux can be installed and run by relatively non-nerdy people, just as Windows and Mac can be. This should be advertised and practised. And I am the prophet, coming from the east, who shall lead the way.  :)
Growing up from childhood and becoming an adult is highly overrated.

Jason

I mentioned above, Buster, that desktop users generally won't have to use the CLI. That doesn't mean there aren't good reasons to do so sometimes.

Some programs, like VMWare, ProtonVPN and Private Internet Access VPN require using the command-line to install/uninstall. But the information is given so it's not hard to do. Ctrl-C + Ctrl-V and you're done. Well, if you know how to find the terminal on your machine, it is. :) Btw, Ctrl-C + Ctrl-V is a combo EVERY computer user should know (I think it's slightly different on the Mac). It's one of those things that some people are surprised to learn that can same them a lot of time. Also, with some programs, it's the only way to paste elements into it.

We didn't mention it but it seems like most graphical updater programs don't remove packages that are no longer needed. But running this command will:

$ sudo apt autoremove

I think Bill ran it once under Linux Mint and it gave him back a gigabyte of disk space. Try it yourself and see how much you get back. If you're been using the distro for a long while, it's likely a lot. Sure, drives today are big but some people are still using computers with small, or nearly full drives already (gamers, torrentors, etc.). There are probably graphical programs that do this. But in terms of time use, is it faster to find such a program, install it and then have to run it, let it load and find the menu item that does it or just run that command which takes a few seconds?

Honestly, I think most people that have encountered Linux know they don't have to run terminal commands but, like with Windows, you can't call yourself a Linux guru or even an advanced Linux user w/o knowing some. I agree that a desktop-user of Linux will rarely if ever have to use the CLI. You're just a better Linux user if you do and can't count yourself as a real guru. There are a lot of Windows tricks that you can do with Powershell, too.

The main reason more people don't use Linux is inertia. They won't change because Windows works "good enough" and they don't know there are OSes that handle the drawbacks they put up with. Or because they're used to the programs in Windows and they're not available in Linux (i.e. MS Office). Of course, LibreOffice is great but if you need to share files with others (who are addicted to MS Office), it's still not 100%.

But people who have never used a computer find Ubuntu Desktop very easy to use. Unfortunately, there's not a lot of those people. I don't know if there is anything you can do to get those users (the vast majority) to even try Linux any more than you can convince the anti-vaxxer crowd to get their damn shots.
* Zorin OS 17.1 Core and Windows 11 Pro on a Dell Precision 3630 Tower with an
i5-8600 3.1 GHz 6-core processor, dual 22" displays, 16 GB of RAM, 512 GB Nvme and a Geforce 1060 6 GB card
* Motorola Edge (2022) phone with Android 13

buster

"Some programs, like VMWare, VPN............. require using the command-line to install/uninstall"

Only in Linux. not in Windows, at least in my experience. VMWare install is point and click. If you want a VPN and a virtual in Linux, yes. However very few home users use virtual anyway.
Growing up from childhood and becoming an adult is highly overrated.

Jason

Quote from: buster on September 07, 2021, 10:46:33 AM
"Some programs, like VMWare, VPN............. require using the command-line to install/uninstall"

Only in Linux. not in Windows, at least in my experience. VMWare install is point and click. If you want a VPN and a virtual in Linux, yes. However very few home users use virtual anyway.

Sorry, aren't we talking about Linux? I thought your point was that you didn't need to use the command line. And most of the time, that's true, probably 99% of the time. But if you want to be an expert user/guru, you should learn the command line. It's so easy a child could do it, honestly. If we want everything to be really easy, we should all just use Macs.

* Zorin OS 17.1 Core and Windows 11 Pro on a Dell Precision 3630 Tower with an
i5-8600 3.1 GHz 6-core processor, dual 22" displays, 16 GB of RAM, 512 GB Nvme and a Geforce 1060 6 GB card
* Motorola Edge (2022) phone with Android 13

buster

For newcomers we should assure them that the command line is not needed, which is true. However the eager adopters would revel in it and adopt it. The note in the magazine suggested users should not be directed to Linux because it REQUIRES knowledge of the command line. Friends of mine still believe this.

The uninitiated should be disabused of this fallacy.
Growing up from childhood and becoming an adult is highly overrated.

Jason

Quote from: buster on September 07, 2021, 02:38:49 PM
For newcomers we should assure them that the command line is not needed, which is true.

Yep, I believe I said as much. Was this a Linux magazine? If so, I doubt noobs interested in Linux would bother to read such a magazine.
* Zorin OS 17.1 Core and Windows 11 Pro on a Dell Precision 3630 Tower with an
i5-8600 3.1 GHz 6-core processor, dual 22" displays, 16 GB of RAM, 512 GB Nvme and a Geforce 1060 6 GB card
* Motorola Edge (2022) phone with Android 13

fox

I agree with Jason about Linux Magazine. I got it for about a year after Linux Voice collapsed and my subscription got transferred. Much more technical than former Linux Voice, or Linux Format (which I now get online through the public library). Only about 1/4 of the articles were of any interest to me; most of the others were for IT people. I stopped getting it when my subscription expired.
Ubuntu 24.10 on 2019 5k iMac
Ubuntu 24.04 on Dell XPS 13

Jason

Quote from: fox on September 08, 2021, 08:08:59 AM
I agree with Jason about Linux Magazine. I got it for about a year after Linux Voice collapsed and my subscription got transferred. Much more technical than former Linux Voice, or Linux Format (which I now get online through the public library). Only about 1/4 of the articles were of any interest to me; most of the others were for IT people. I stopped getting it when my subscription expired.

I meant a Linux magazine, not the Linux magazine but I hope you can still agree with the point I was making. :) And yes, Linux magazine was quite technical. When I stopped writing articles for the Kawartha Computer Club newsletter years ago, the board gave me a subscription as a gift. I think I only read Marcel Gagne's column ("Cooking with Linux"). The rest of it was too technical for me or really just referring to software I didn't use. I think they were targeting Linux system administrators, not the average users. At that time, probably 99% of the Linux users were sysadmins!
* Zorin OS 17.1 Core and Windows 11 Pro on a Dell Precision 3630 Tower with an
i5-8600 3.1 GHz 6-core processor, dual 22" displays, 16 GB of RAM, 512 GB Nvme and a Geforce 1060 6 GB card
* Motorola Edge (2022) phone with Android 13

buster

"Was this a Linux magazine? "

No. Pretty sure it was PCMagazine with an article on Win11. Quite a few of the comments after the article pointed out that the new physical requirements would necessitate the purchase of new computers. And of course Microsoft makes no money with upgrades. It was an orderly and rational discussion.

Then someone suggested switching to Linux. And that's when the comment about NEEDING to use the command line was written.

No one  contradicted this assertion.
Growing up from childhood and becoming an adult is highly overrated.