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 ?
5
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.
2
u/Paul_Pedant May 20 '26
If you do care about the order, then for any text file less than 100 MB:
awk '! X[$0]++'
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 folder x. At least that is the last thing it does. First, it descends through the entire subtree of all the files and folders below x, and destroys all those.
rm -rf * is much more brutal. The * is a wild-card meaning "all objects in the current directory". The -r means "the entire subtree of every object, including all its sub-directories, and then the current directory itself". The -f means "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 $x means that the name is take from a variable x, 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 sends SigTerm to the process, which can set up its own rules about what to do. It is not clear that ID has 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_PACKAGES
For example:man man
MAN(1) Manual pager utils MAN(1)
NAME
man - an interface to the system reference manuals
SYNOPSIS
man [man options] [[section] page ...] ...
man -k [apropos options] regexp ...
man -K [man options] [section] term ...
man -f [whatis options] page ...
man -l [man options] file ...
man -w|-W [man options] page ...
DESCRIPTION
man is the system's manual pager. Each page argument given to man is normally the name of a program, utility
or function. The manual page associated with each of these arguments is then found and displayed. A section,
if provided, will direct man to look only in that section of the manual. The default action is to search in
all of the available sections following a pre-defined order (see DEFAULTS), and to show only the first page
found, even if page exists in several sections.
The table below shows the section numbers of the manual followed by the types of pages they contain.
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions, e.g. /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7), man-pages(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
A manual page consists of several sections.
Conventional section names include NAME, SYNOPSIS, CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS, RE‐
TURN VALUE, ERRORS, ENVIRONMENT, FILES, VERSIONS, CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and SEE ALSO.
The following conventions apply to the SYNOPSIS section and can be used as a guide in other sections.
bold text type exactly as shown.
italic text replace with appropriate argument.
[-abc] any or all arguments within [ ] are optional.
-a|-b options delimited by | cannot be used together.
argument ... argument is repeatable.
[expression] ... entire expression within [ ] is repeatable.
Exact rendering may vary depending on the output device. For instance, man will usually not be able to render
italics when running in a terminal, and will typically use underlined or coloured text instead.
The command or function illustration is a pattern that should match all possible invocations. In some cases
it is advisable to illustrate several exclusive invocations as is shown in the SYNOPSIS section of this manual
page.
EXAMPLES
man ls
Display the manual page for the item (program) ls.
man man.7
...2
1
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
1
u/WolfWildWeird May 21 '26 edited May 21 '26
grep "str" file.ext
killall ProcessName
df -h
echo "a:b:c:d" | cut -d':' -f2 # = b
# bash aide
help
help exec
pushd /etc
...
popd # Retourner au dossier avant "pushd"
alias lsa='ls -al'
alias lsac='lsa --color=auto '
# L'espace à la fin est nécessaire lors de l'utilisation d'un alias dans un alias.
alias -p > ~/.bash_aliases
more
less
head
tail
yes
...
1
0
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
2
u/pizzacake15 May 18 '26
If you ever need help with touch you can type in man touch 😉
0
u/KlePu May 18 '26
I've googled "man curl" once too often ;-p
1
0
May 18 '26
[deleted]
0
u/KlePu May 18 '26 edited May 18 '26
Just tried in a private browser window: Google
man grepare only actualgreppages (man7.org, die.net, gnu.org, ...) on the first page, no suggested images or AI.
man curlOTOH yields mostlycurlrelated pages - but also some images of men's haircuts, along AI follow-ups that just now lured me into the rabbit hole of "zottman curls" ;-pedit: Got curious...
man finger: Nothingfingerrelated (was to be expected I guess)
man signal: Mostly actualsignalmanpages - and Signal messenger obviously ;)
man kill: ..ok sorry, guess Google does detect and use your OS to filter results... This only yieldedkillmanPages and a few shutterstock images at the very bottom =/
0
May 18 '26
[deleted]
3
u/LogicalWrap3405 Bash May 18 '26
Thanks for that , is so useful for me
4
u/ktoks May 18 '26
It might be good to make another list that includes IO information: piping (|), writing to (>), reading from (<), concatenation (>>), and various command substitution and tricks such as $(some command) and <(some command) and when they are beneficial.
Flags to show errors (set -x)-helpful for debugging - or stop short if one occurs (set -e).
Maybe another for language structures such as forloops, if statements, while read, functions, and how to parse command line arguments.
One for customizing environmental configurations such as: adding executables to $PATH, aliases to shorten often-used commands, cd - to go back to the last directory, ctrl-r to find past commands(perhaps even fzf upgrade for this feature), and turn on history search so you can partially type a command, then hit up to reverse search your history to find complex commands quickly.
Another for various other tools such as zip, unzip, tar, pgp, gzip, rar, vi/vim/nvim, file, head, tail, watch, cmp, make, git, and xargs.
And lastly - for networking: ssh +configuration with public and private keys for secure, password free access to remote servers, scp, rsync, ping, and ss.
-1
May 18 '26
[removed] — view removed comment
3
u/LogicalWrap3405 Bash May 18 '26
i think is good to note everything you did or you learn.
3
May 18 '26
[removed] — view removed comment
4
u/LogicalWrap3405 Bash May 18 '26
yes is my first week on Linux.
2
May 18 '26
[removed] — view removed comment
0
u/LogicalWrap3405 Bash May 18 '26
can u explain more ??
0
u/profadept May 18 '26 edited May 18 '26
Meaning, you go into your .bashrc to paste these aliases(aliases in Linux are just a way you create a shortcut to a long command) he mentioned. He added options/flags that changes the way the command behaves( The i flag means interactive, i.e it asked you for confirmation before executing the commands, you can also add -v too which is verbose to display all the operations it's doing on the screen) and these are just almost daily commands you use as a regular Linux User.
Steps to get it to start working.
Step one:Open your shell(bash, zsh) using your editor of choice (nano, vim, micro) Command: nano ~/.bashrc
Step 2: Paste those aliases he suggested below the bashrc. NB: after some time with Linux you can create a file in your home directory called .bashrc_aliases and configure it in your bashrc so your bashrc can be clean and you can use that bash_aliases file anywhere with just configuring it in the shell configuration file (bashrc, zshrc) of the new Linux PC.
Step 3: Reload your bashrc to read the new commands. Command: source ~/.bashrc
Then you can start using the aliases immediately. mv source destination cp source destination rm filename mkdir dir-name ln target-file link-name ping website
You can read about the aliases command usage online or download the "Linux Command Library" app on F-Droid. It is a very useful handbook for anyone learning Linux and is available offline.
8
u/KlePu May 18 '26 edited May 18 '26
Nice base! Some typos/suggestions:
rm-ris missing a spacewhy both
rm -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 timestampsyou have
lsandls -lbut nols -a(orls -la) for hidden filesechois used to show variables' values outside of scriptsyou have
tree(which is not a baseline program) - consider addingncdufor
findI'd use-iname(case insensitive)wc(with no flags) outputs lines/words/bytes all at oncegrep 'word'appears twice (second one is incomplete)note that single quotes will stop any bash globbing or expansion!
su root: usesu root -(orsu -) instead to also change ENV accordingly (else/usr/sbinwill not be in your$PATHfor example)while we're at it:
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 output