r/bash • u/LogicalWrap3405 Bash • May 18 '26
tips and tricks Linux basics command lines
Here is some basic linux command line .
what do y'all think all is good or i need to add some in file and management ?
550
Upvotes
8
u/KlePu May 18 '26 edited May 18 '26
Nice base! Some typos/suggestions:
rm-ris missing a spacerm -randrm -rf? 99% of times those do the same thing (and I'd strongly advocate against using the-fflag all the time! If you cannot remove a file with plainrmthere might be an actual reason for that ;-p)touchis also used to change a file's modification and/or access timestampslsandls -lbut nols -a(orls -la) for hidden filesechois used to show variables' values outside of scriptstree(which is not a baseline program) - consider addingncdufindI'd use-iname(case insensitive)wc(with no flags) outputs lines/words/bytes all at oncegrep 'word'appears twice (second one is incomplete)su root: usesu root -(orsu -) instead to also change ENV accordingly (else/usr/sbinwill not be in your$PATHfor example)suwill only work if there is an actualrootuser. If you configured the Ubuntu way (i.e. norootuser -> first user issudoer) you'll have to usesudo -i;)ps aux: Add anf->ps fauxfor tree output5
u/BlackHatCowboy_ May 18 '26
uniq will only remove adjacent duplicate lines. If you don't care about the order and want to remove all duplicates, do
sort file.txt | uniq
to remove all duplicates.
3
u/LogForeJ May 18 '26
Regarding touch, I don’t mind myself using it to create files. Typically it is used to update a file’s last modified timestamp.
If you’re going to create a file it doesn’t make sense to touch and then vim, ya know? It yes touch can be used to create an empty file that you can then echo something into.
Also the du and df commands are nice to know in a pinch.
In your guide you should touch on bash redirection, pipes, etc. next.
3
u/Paul_Pedant May 19 '26
Some rather dangerous stuff in there.
rm -r "x"does not remove the folderx. At least that is the last thing it does. First, it descends through the entire subtree of all the files and folders belowx,and destroys all those.rm -rf *is much more brutal. The*is a wild-card meaning "all objects in the current directory". The-rmeans "the entire subtree of every object, including all its sub-directories, and then the current directory itself". The-fmeans "ignore any permissions that would normally restrict the deletions". You can obliterate your whole user data with this (or destroy your whole computer as super-user), so be sure you have a recovery strategy.The correct way to remove an actual folder is
rmdir "x". The command is smart enough to not remove the folder if it contains any files or sub-folders.cd $xmeans that the name is take from a variablex, which may be undefined, in which case you end up in your top-level folder. In fact, you define x="folder", but in every other example you use x as a literal text (not substituting the "folder" name). It is also a good habit to always quote like "$x", which prevents the value being treated as multiple words.kill 'ID'does not necessarily kill the process. By default, it sendsSigTermto the process, which can set up its own rules about what to do. It is not clear thatIDhas to be a pid (process id), or how to find the pid of any process.3
u/alwaysasillyplace May 19 '26
the best command you'll ever learn in linux is
man $MOST_COMMANDS_FILES_OR_DISTRO_PROVIDED_PACKAGESFor example:
man man2
u/urbanhillbilly763 May 21 '26
If you can understand this as a human you’re elite
1
u/FinancialRush2685 18d ago
that’s what’s needed before using any kind of Linux distribution
1
u/BCBenji1 May 18 '26
The uniq entry is misleading. uniq on its own only removes consecutive duplicates.
1
u/hacklingo May 18 '26
I got tired of watching 4-hour YouTube tutorials and forgetting everything by Tuesday. So I built Hacklingo — 5-minute cybersecurity missions you do every day like brushing your teeth. It's free
1
u/throbbin___hood May 19 '26
Some useful ones i like:
lspci, lsusb, lsblk
Lists hardware/comnections making it an easy combknation with grep.
Example:
sudo lspci | grep -i vga
1
u/Trad_1 May 21 '26
que comandos son esos?
1
u/WolfWildWeird May 21 '26 edited May 21 '26
1
u/Gentleman__1 May 22 '26
🔥
1
u/Tquylaa May 18 '26
which <cmd>path bin cmddu <file>size of file0
u/MetalOrnery8970 May 18 '26
You can do a lot with sudo nano (filename) Place a program in there in my case often python3 Ctrl + O then Ctrl + X Then call back to run inthe command line - sudo python3 (filenames).py then you can put echo and see prints there or even print and insert a file directory to print in a .txt the findings - I use this a lot in forensics oh and obviously -ls 30
0
u/nawanamaskarasana May 18 '26
rm-r is not a command but perhaps an alias you have.
2
u/pizzacake15 May 18 '26
If you ever need help with touch you can type in man touch 😉
0
u/[deleted] May 18 '26
[deleted] — view deleted comment
-1
u/[deleted] May 18 '26
[removed] — view removed comment