Doubt On Linux Commands

Many times on this site we drop to command line to get something done. Guess that in some cases is easier than selecting, menu, control panel, updates etc especially as not every version of linux interface gui has that option in that place. So things like
sudo apt-get update etc.

I use mint debian and spend 99 % of my time in the gui.

Do many of the commands change if I move to another linux ?
Is the same basic stuff the same ?
Do I need to relearn linux to get to the same level ?

I am thinking change directory, copy files, do updates, install a application, etc

Just as a follow up…
Favourite linux command ?
Most used command ?

This for me would be fsck… not reciently but during a period at least once a week came into play.

Many years ago I bought the book written by a fellow member of the community, it sits on my desk and goes with me to clients falling apart and ready to buy the new version, but resist as I have so many scribbled notes everywhere would be difficult to copy.

Linux pocket guide daniel barrett.2012.

I know cheat sheets exist but never bothered to print one prefer the book.

5 Likes

I use Mint Cinnamon and also use the GUI 99% of the time. I can get all things I do daily thru the GUI. So going to the CLI is the exception. I did read some where that almost all CLI commands are universal in the Linux world.

4 Likes

Mostly the commands don’t change.

The package manager changes, so if you move from Debian to Fedora the update would change.

sudo apt update && sudo apt upgrade -y

sudo dnf update -y

The commands to change directory, create directory, copy files, list files, etc. Those are all the same with largely the same options. I’m sure there are exceptions, but I haven’t run across any I can recall.

Going from older versions of linux to newer versions sometimes makes a difference. Some commands are deprecated and replaced with a new preferred command.

netstat -an
ss -tuna

ifconfig
ip address

Those are basically the same but netstat and ifconfig have been deprecated for years. Some distros may remove them or not install them by default. Ubuntu doesn’t have ifconfig or netstat installed by default. They’re installed with the net-tools package.

There is also busybox. That’s a set of commands like cp, ls, and tons more that are normally used in containers and similar environments where space is at a premium. The commands are the same but only a subset of options are included.

4 Likes

The core utilities do not change from linux to linux. They are slightly different in BSD.

https://www.gnu.org/software/coreutils/

Updates and install packages are not core utilities. They will change if the distro has a different package system.

The shell (default) may change with distro. You can always install your favorite shell.

Most used command : ls
Note cd is not a command… it is part of the shell

3 Likes

Most of the “commands” I use are external binaries - i.e. not necessarily “Linux”.
Probably rsync *, and (p)rename… and maybe ffmpeg… and systemctl… and of course apt… I do maybe 75% or more of stuff in the shell (zsh in my case) - don’t often use the filemanager, and more often that not - if I’m running the filemanager (e.g. files in Ubuntu / Pop!) I’ll right click and “Open in terminal” to continue doing stuff…

There are a few differences in the “families” - e.g. Debian VS Red Hat…

Debian busybox doesn’t have vi (you can only use nano)
Red Hat busybox does have vi

Busybox version of “cat” doesn’t display line numbers -i.e. “cat -n filename” won’t run 'cause there’s no “-n” option in that version of cat… That’s super annoying in e.g. busybox in MobaXterm (i.e. cygwin busybox) - I sometimes need to see what line number in my ssh config files might be the issue (e.g. in MobaXterm ~/.ssh/config and ~/.ssh/known_hosts.

And I’ve mentioned before “rename” command (package) in DEB based distros is different to the one in Red Hat derived distros. (p)rename in DEB is the perl rename utility from CPAN, and supports sed style regex, Red Hat (e.g. Fedora, Oracle, RHEL, CentOS) rename is a completely different beast to perl rename - but you can install perl rename on them (don’t remember how exactly - i.e. which RPM package hosts it) - one time I needed it was able to install it from the CPAN perl repository (so long ago now I don’t remember the exact syntax).

I don’t currently have any Red Hat distros I can access quickly to verify how I installed (p)rename. I haven’t powered up my Gigabyte Brix mini-PC with RHEL8 for a couple months now. I’m on Xmas break leave - so not going to connect to any customer systems to verify… I do have a few RPM based VM’s in QEMU / UTM on Mac and virtualBox on Linux, but I don’t think I’ve ever installed (p)rename on them…

* rsync : I often think like I’m using “cp” and forget “-av” switches… I just now made an alias :
alias rink='rsync -av'
I tend to use rsync a lot more than cp, but one thing I prefer about “cp” is you can change the name of the destination, if the source is a directory - what rsync does is create a new folder if that doesn’t exist, and copy the source folder as a folder, into that new dir. I prefer cp behaviour when it comes to that…

e.g.
cp -r ~/Downloads/MusicFolder ~/Music/NewMusicFolder
will copy the dir “MusicFolder” to ~/Music/. but name it “NewMusicfolder”
rsync -av ~/Downloads/MusicFolder ~/Music/NewMusicFolder
will copy “MusicFolder” to ~/Music/NewMusicFolder/MusicFolder (i.e. it will create directory ~/Music/NewMusicFolder if it doesn’t exist).

I also use “find” all the time too - but I kinda hate how clunky it is… obtuse… kinda stupid… like if you use the “-exec” switch - you have to append a “\;” to the end of the find command to make it exec on each file it finds… And half the time switches like “-xdev” or “-mount” don’t do what they’re supposed to - e.g. I want to find files larger than 128 MB on the whole dir structure of “/” - BUT - not NFS or SMB mounts, and NOT other mountpoints :
find / -xdev -size +128M
in many cases it will work (e.g. it won’t traverse /var if it’s a separate mount) - but in other cases even though you explicitly told it to stick to “/” - will will interrogate other mount points! And worst of all - it will interrogate /proc (and barf on every attempt to traverse the /proc subfolders). So - if you want to exclude specific folders - you have to use MULTIPLE “prune” commands - that’s bullshit and makes it very unwieldy (especially at 3 am when you’ve just been paged for a disk space alert). So - I try to avoid using “find” in that use case - invariably anway - it’s probably going to be something in /var - so I use “du” instead - e.g. “du -sh /var/ |sort -h”, or “du -d 1 /var/ | sort -h”

6 Likes

locate is more friendly

https://linux.die.net/man/1/locate

Here is a list of commands you can guarantee are always there in any GNU/Linux

4 Likes

A list of rewritten commands in Rust. I’ve use fd for find and ripgrep for grep.

3 Likes

Nice - my main issue is that I have literally 1000’s of machines I do sysadmin on - many still running RHEL6 or 7, with no internet access, some of them OT environments (e.g. SCADA)…

So I have to use what’s there :smiley: - no way to install modern stuff on these pieces of crap…

I should bookmark that list - and check some of it out later…I could run much of that stuff on that page on my home lab Linux machines (and MacOS).

And don’t get me started on Solaris GRRRRR! Oracle pretty much made it an unusable megalithic piece of crap when they banned/blocked Sunfreeware… No more GNU tar or find… Solaris 11 is slightly better - but still HIDEOUS to use VS something like RHEL8 and 9 or Ubuntu 20, or Debian 12…

3 Likes

Thats great to know.

I have never needed to install or use this, think my programming days are over for what i need to do, just simple stuff.

2 Likes

@nevj and all:

Hi Neville, :wave:

true, but there´s also fdfind, which I like a lot.

env LANG=en_GB:en apt-cache show fd-find
Package: fd-find
Architecture: amd64
Version: 8.3.1-1ubuntu0.1
Built-Using: rust-nix (= 0.23.1-1), rustc (= 1.59.0+dfsg1-1~ubuntu2~22.04.1)
Multi-Arch: allowed
Priority: optional
Section: universe/utils
Source: rust-fd-find
Origin: Ubuntu
[...]
Homepage: https://github.com/sharkdp/fd
Description-en: Simple, fast and user-friendly alternative to find
 While it does not seek to mirror all of find's powerful functionality,
 fd provides sensible (opinionated) defaults for 80% of the use cases.
Features:
 * Convenient syntax: ??fd PATTERN?? instead of ??find -iname '*PATTERN*'??.
  * Colorized terminal output (similar to ls).
  * It's fast, often faster than find.
  * Smart case.
  * Ignores hidden directories and files, by default.
  * Ignores patterns from your .gitignore, by default.
  * Regular expressions.
  * Unicode-awareness.
  * Parallel command execution with a syntax similar to GNU Parallel.
[...]

Many greetings from Rosika :slightly_smiling_face:

9 Likes

Hello Paul

Due Java programming working with STS4, Maven and Gradle. I did do some scripts to work with Ubuntu, Fedora and Debian. So far no problems about portability.

But yes, exists difference(s) about behavior. So far I remember a difference about creation of users between Ubuntu and Fedora. In ubuntu is enough use a command, in Fedora more. It because the former uses other behind the scenes

Something important to consider is the bash version too.
I had issues about portability between macOS and Linux because was not possible for me upgrade macOS. Other consideration would be if exists differences or not between sh and zsh too

Furthermore is different the options about “acl” in macOS against Linux

Thus, when I try a new Linux distribution or set of scripts among distributions I use a Virtual Machine such as VirtualBox for testing and avoid lost of data in a direct installation

About GUI vs command. I think it is according the scenario: the latter is better to create a hierarchy of directories and set permissions once (it for a new installation). Would exists other scenarios? I think yes. Furthermore for a quick and simple situation: How to do a ping in the same LAN through GUI?

About scripts: of course, it requires a good amount of time to write and test for “refactoring”.

1 Like

It does indeed. You seem to be writing scripts that involve filesystem parameters like acl. That will vary if distros use different filesysyems.

I have some portability issues with scripts between bsd and linux… but I usually only write very simple scripts, so it is not a bother.

https://www.makeuseof.com/visualize-ping-responses-on-linux-with-gping/

5 Likes

Hello Neville

It does indeed. You seem to be writing scripts that involve filesystem parameters like acl. That will vary if distros use different filesysyems.

About the scripts yes mostly about the mkdir and chmod commands. It applies for groups too (secondary groups)

About “ACL” was not applied in scripts, only manually

Apart. Now I remember about the kill command, there is an option to list all the signals and their purpose, I remember clearly the list was different between macOS and Ubuntu.

I have some portability issues with scripts between bsd and linux… but I usually only write very simple scripts, so it is not a bother.

I am agree too. But always is import do testing

https://www.makeuseof.com/visualize-ping-responses-on-linux-with-gping/

Thanks for the link

2 Likes

MacOS has the BSD core utilities. Ubuntu has the GNU core utilities. They are different. See my Chimera… topic, it is discussed there.

2 Likes

MacOS has the BSD core utilities. Ubuntu has the GNU core utilities.

Yes, something important to be take it in consideration

Some specific link was forgotten to be share?

1 Like

There is a section titled “BSD core utilities”

2 Likes

As usual

Thank You

2 Likes

I don’t use or need to ping anything, must be 2 years at least since I tried, and that was just to get to a router that was playing up , but that I did through the browser line in google chrome 192.168.1.1, now the company offer a app so not often needed, although not a linux version.

1 Like

Same here - I have a few scripts I run on either FreeBSD (TrueNAS) or MacOS or Linux…
For those ones I use a case statement… e.g.

#!/usr/bin/env bash
OS=$(uname -s)
PROF="crt-lottes"
PROF=""
HOHO="REDACTED"
case $OS in
	Linux)
		/usr/bin/mpv --no-border --mute=yes http://$HOHO:9981/playlist/channels &
	;;
	Darwin)
		/opt/homebrew/bin/mpv --mute=yes http://$HOHO:9981/playlist/channels &
	;;
	*)
		echo "don't bother trying that stuff here... exiting..."
		exit 1
	;;
esac

Above is to stream TVHeadEnd free to air TV running on a Pi3 with Debian 9 (Stretch) - I used to use VLC - but found MPV a much better solution…

Been a while since I had scripts across FreeBSD too, but I used to… Actually - my old password system was set to run on all three NIX I run at home - most of the stuff in here is redacted :

MACHT=$(uname -s)
...
ARGLE="$1"
case $MACHT in
	Darwin)
		export BBIN=REDACTED
	;;
	Linux)
		export BBIN=REDACTED
	;;
	FreeBSD)
		export BBIN=REDACTED
	;;
	*)
		echo "anything else not supported here... so why don't you REDACTED off"
		exit 1
	;;
esac
...

Above only 'cause the full path location of the script (the same script) is different on each above…

Also note : nearly every script I write - have the hashbang (AKA “shebang”) as “#!/usr/bin/env bash” - but have very occasionally found older systems (I don’t think I have any left now) where that caused issue and had to revert back to “#!/usr/bin/bash” (but e.g. on FreeBSD - bash isn’t there - so it’s “#!/bin/bash” - but on FreeBSD (at least on mine) “env” is in /usr/bin/ …

3 Likes

What does env do?
I am really archaic… still use sh instead of bash.

1 Like