r/linuxquestions • • Oct 17 '20

Your best LTP (Linux Pro Tip)

What is your best Linux Pro Tip?
Settings or scripts that make life easier, secure, or nicer.

To kick it off: I started using a temporary directory in my home dir to save documents that I don't need to keep forever, but unlike /tmp are maintained across reboots. It keeps my files from cluttering up.

192 Upvotes

267 comments sorted by

103

u/[deleted] Oct 17 '20

!! is the last command you ran, so when you forget sudo simply do sudo !!

27

u/spryfigure Oct 17 '20

Last argument is !$, and you can go through the last commands' arguments with <Alt-.>. It also pays in both cases to have shopt -s histverify in your .bashrc. You can review one more before you commit with a second <return>.

3

u/[deleted] Oct 17 '20

Thanks for mentioning that, I always forget what that shortcut and searching online for it always tended to not give me the right result.

4

u/Atralb Oct 17 '20 edited Oct 18 '20

r/GNUReadline has all the docs for you.

And I'm pretty sure you didn't find the appropriate doc because you didn't have the keyword "Readline". That's the actual program that parses your key inputs on a bash shell. It's indeed very seldom known nowadays. I strive to change that :p

8

u/[deleted] Oct 17 '20

And this only works with POSIX compliant shells. For example, fish doesn't have this but can be configured in

2

u/nanowillis Oct 17 '20

This annoyed me at first, but I quickly found it was faster to just use vim bindings to jump to the last command and edit however I needed it

2

u/[deleted] Oct 17 '20

I don't remember why but I didn't get on with fish, I'm currently using zsh. I do this most of the time but I still think it's easier sometimes doing !!

→ More replies (2)
→ More replies (2)

1

u/Megame50 Oct 18 '20

History expansion is not POSIX. Some shells implement it and some do not.

7

u/kaerock Oct 17 '20

I've never found the ! functions useful. Doing command history math is just too hard (wait, was it four commands ago? three?). You know what's easier? Up-arrow. It even takes less typing and only one hand :) After a few up-arrows and I haven't found my command, I go for 'control-r' then start typing the pattern.

10

u/crosenberg_0630 Oct 17 '20

Sure, trying to remember how many commands ago you entered something isn't so productive, but the '!' commands are useful when combined with the history command.

"I know I entered some specific and hard to type command in the last 20 commands..." history | tail -20

"Ah, it was command number 487." !487

Even more useful when you can only remember part of the command, and you pipe history through grep. You can find extremely esoteric stuff from several days ago that way.

4

u/ErebusBat Oct 17 '20

FZF with history search. I miss that more than my vimrc on systems now

2

u/kaerock Oct 17 '20

Yea, I totally get that, it has its place. I use it fairly rarely but it's always with a 'history | grep' or some such if control+R is being pain in matching. I think more my point is that it's a bit of an advanced feature in that it requires more thinking to utilize than say, an arrow key.

1

u/Atralb Oct 18 '20

You don't understand the purpose of history expansion.

They are not to be used alone as a sort of redundant alternatives for the history command browsing. They are to be used within complex commands to be referenced arbitrarily, and most interestingly multiple times. Using Ctrl-P (or Ctrl-R) to go to the last history command is meant for a totally different usage: running the exact same command again or modify just a part of it.

However if you want to do something like:

echo "!!" ; command1 $(!!) | command2 !^ 

then history expansion is highly superior. Why because the first expand the command in history right away, while the other is simply a reference to it. Two completely different paradigms.

→ More replies (1)

0

u/[deleted] Oct 17 '20

[deleted]

→ More replies (1)

2

u/[deleted] Oct 18 '20

In Ubuntu, you press up button in terminal and the last command you ran pops out

39

u/KvotheSonOfArliden Oct 17 '20

One step at a time. Don't immediately jump into r/unixporn and start copying dotfiles that you don't even know what they are.

Install the OS first, figure out what are things that you absolutely need on your computer and install it (stuff like your favorite browser or dropbox). Go on with your life and experiment from there a bit.

110

u/aaronryder773 Oct 17 '20

My best LTP is for beginner users: Try doing everything using CLI. Sure it will be a pain at the beginning but it will be worth it.

18

u/[deleted] Oct 17 '20

Care to explain why?

73

u/patatahooligan Oct 17 '20
  • ultimately faster

  • way more portable (compare how long APT has been around and how the interface has changed with GUI package managers, also think about how much easier it is to copy an APT command from a tutorial vs following a dozen pictures of windows with arrows pointing to the button you need to press)

  • script-able so you can automate & customize stuff

  • better control over what it does, so less likely to bork your system with no indication as to why

  • usually much clearer feedback/logging, has the same benefit as the above point + you can copy-paste it into a thread asking for help

  • much simpler so usually fewer bugs, especially when the gui is just a frontend to the same cli tool you would be using

39

u/[deleted] Oct 17 '20

following a dozen pictures of windows with arrows pointing to the button you need to press

And we've all been there when the only guide you can find is from a different version than the one you're running and all the buttons are in different places or straight up not there or renamed

9

u/[deleted] Oct 17 '20

i sussed out a display issue in arch using a debian-based guide. that was fun

also i got the linux bible and its for fucking redhat. my linux journey has been like rolling down a fucking hill

6

u/[deleted] Oct 17 '20

Yeah I use guides from all distros for every other distro, you just have to know how each distro does certain things, guess all the distro hopping I've done this last year pays off in some ways

→ More replies (4)

12

u/m477m Oct 17 '20

Once you get used to the command line, it gives you "power tools" to do repetitive things much faster than the "hand tools" of the GUI can.

For example, just yesterday for my day job, I needed to create 24 folders with names along the lines of folder01, folder02, folder03, ... folder24.

I mean, sure you can create all those folders in your file browser by hand, but it's MUCH faster to just:

for i in $(seq -w 01 24); do mkdir folder$i; done

Then I had to sort 900+ files all in one big folder, named something like category01-file01.mp3, category01-file02.mp3, ... category01-file17.mp3, category02-file01.mp3, .... category24-file13.mp3.

Each category had to go to its like-numbered folder. Sure, I could click the first file of a category, shift-click the last, and drag them to the folder... 24 times in a row... or I could just:

for i in $(seq -w 01 24); do mv /path/to/big/folder/category$i*.mp3 /path/to/individual/folder$i/ ; done

The first time I thought to do something like that, years ago, it took much longer to research how to do it, and experiment with commands to figure it out, than it would have taken to just do it by hand.

But that's where the investment of time comes in. Because I spent more time learning the command line in the past, I know what to do to save a ton of time for would-be tedious tasks now.

4

u/[deleted] Oct 17 '20

I watch a lot of anime that I download, and on Windows it would involve downloading a bunch of shows every season, then sorting them manually into directories. So that would mean hand making a new directory every time I got a new show, then taking each one and sorting them into their directories every time an episode released.

I eventually automated that with a Python script. Then moved to Linux and changed the script from Python to Bash. The Bash script accomplished the same task in less than half the lines, and less complexity. It can take basically any show, figure out what part is the relevant title most of the time, create new directories as needed, and always sort each show into it's directory.

Yesterday I automated the process of updating my dwarf fortress, and wrote a bash script to pull the latest version of the game, along with the latest versions of dfhack and twbt into a temporary directory in /tmp, then it backs up my configs, saves, and art, installs the game and mods where they each need to go, then puts my play data back.

The shell and shell scripting are amazing.

→ More replies (3)

3

u/Sophira Oct 18 '20

I mean, sure you can create all those folders in your file browser by hand, but it's MUCH faster to just:

for i in $(seq -w 01 24); do mkdir folder$i; done

In this particular case, you can go even better. In bash - and I think most shells, but I don't know for sure - you can do this instead:

mkdir folder{01..24}

No for loop required, and yes, the leading zeroes are preserved!

→ More replies (2)

2

u/atomicxblue Oct 17 '20

I wrote a bash script that loops over video files in a directory and runs them through ffmpeg. It was taking forever doing it manually, but now I can just copy what I want to convert, call the script and play video games or something.

19

u/KvotheSonOfArliden Oct 17 '20

I think that doing things using CLI is generally faster than using the mouse or a GUI in most cases. Coming from Windows using CLI was cumbersome for me so I get the question.

For example, if you look up a guide on how to do something on windows, you need to go through a bunch of menus and dropdowns? Using CLI is probably just one command.

8

u/Disruption0 Oct 17 '20

+ GUI are limited.

12

u/costagabbie Oct 17 '20

afaik the gui is limited by the designer, a good gui provide the same flexibility of a CLI

→ More replies (10)

17

u/GloWondub Oct 17 '20
  • Works without X server

  • Works over ssh/docker/...

  • Works on all desktop environnement

  • More easy to make it work on a différent distribution

  • Keyboard is faster than mouse

  • Scriptable

  • Let you learn the inner working of the tools and the os.

1

u/TundraGon Oct 17 '20

Sometimes you need to login via ssh into a machine and all you got is the CLI.

2

u/TheTechRobo Oct 17 '20

Adding on to this: using OhMyZsh makes the CLI so much nicer. It speeds up your workflow, makes the terminal look nicer, and ultimately is just a must-have for beginners and experts alike.

1

u/[deleted] Oct 17 '20

wait there's things you can do in GUI besides interface with apps? cuz it feels like everything I do in this mother fucker has to be done in CLI (which I fucking love honestly)

0

u/[deleted] Oct 17 '20

[deleted]

1

u/wikipedia_answer_bot Oct 17 '20

In Greek mythology, Clio (traditionally , but now more frequently ; Greek: Κλειώ, Kleiṓ; "made famous" or "to make famous"), also spelled Kleio, is the muse of history, or in a few mythological accounts, the muse of lyre playing.

== Mythology == Clio, sometimes referred to as "the Proclaimer", is often represented with an open parchment scroll, a book, or a set of tablets.

More details here: https://en.wikipedia.org/wiki/Clio

This comment was left automatically (by a bot). If something's wrong, please, report it.

Really hope this was useful and relevant :D

If I don't get this right, don't get mad at me, I'm still learning!

24

u/TrogdorsArm Oct 17 '20

Tip #n, always make a backup copy of the files you edit. When things go sideways, and they will, you can revert back.

4

u/i_likebeefjerky Oct 17 '20

This one will save you so much time and frustration, I can’t stress it enough.

3

u/funbike Oct 18 '20

Better: use git + gnu stow

https://dotfiles.github.io/

1

u/Aberry9036 Oct 18 '20

And learn the benefit of comments! Select in vim, yank, paste, block-select the new text and comment it out - its not a full backup but it does give you visual reference to the original while editing the new, which is handy if you don't have multiple windows or a mux.

Also, the true purpose of comments, make notes in your config files or code - when you go back there in a year you'll forget what half of it means and break it again.

24

u/vimsee Oct 17 '20

Learn about permissions. Learn the chown and chmod command. Understand the numbers representing permission 1-7. In unix this goes a long way when you cant understand why you cant open, change or delete a file.

2

u/Aberry9036 Oct 18 '20

This is great advice. More advice to go with it is learn what sudo means and when to use it - often users create files they then can't edit or break files they shouldn't because they run commands as root unnecessarily. Also, pretty much never chmod 777 anything, especially if it's not a directory or in unprivileged path - you don't need every user on your computer to be able to read, write and execute that cat gif in your home folder.

24

u/jzbor Oct 17 '20

<Ctrl-u> to clear your input. Pretty nice, when you think you mistyped your sudo password half way through and usually would end up abusing the backspace key...

9

u/jwaspin Oct 17 '20

Also <Ctrl-W> to delete only the last word

2

u/jzbor Oct 17 '20

Nice didn't know that one

4

u/[deleted] Oct 17 '20

This is actually huge! I used to just spam <Ctrl-c> to cancel input.

2

u/pasmon Oct 17 '20

From a colleague I learned to move to beginning of the line and put # there, no need to delete anything.

3

u/Aberry9036 Oct 18 '20

Also ctrl a to get to the beginning of a line, ctrl e to get back to the end again.

1

u/funbike Oct 18 '20

Good. Better: learn the readlink shortcuts. https://readline.kablamo.org/emacs.html

2

u/jzbor Oct 19 '20

Unfortunately only works with readline emacs mode in bash though...

→ More replies (1)

0

u/[deleted] Oct 17 '20

[deleted]

1

u/jzbor Oct 18 '20

That would be pretty nice - unfortunately it doesn't work for me (zsh + alacritty)...

42

u/[deleted] Oct 17 '20

Put your config files under source control. Use symlinks so that the files are accessible where the system needs them. Write good commit messages documenting why you changed things.

17

u/paccio88 Oct 17 '20

And have a look at GNU stow to do this

4

u/[deleted] Oct 17 '20

I don't understand what the point of stow is. It doesn't seem to do much for me that I can't trivially do myself.

10

u/Gornius Oct 17 '20

Home folder is a mess. It's easier to just "stow *" than manually symlink all the files.

8

u/Uhh_Clem Oct 17 '20

I've got dozens of config files to track and about a half-dozen different computers to keep them in sync across. Trust me, Stow starts to get pretty essential.

→ More replies (4)

9

u/jwaspin Oct 17 '20

It’s also nice to have this remotely accessible so you can download it quickly to any new installs and have a script to “install” your config.

I store my dot files under a “dot” repo on GitHub.

Thanks for the symlink suggestion!! Definitely need that.

7

u/estebanyque Oct 17 '20

Also I wrote a simple bash script deploy_config.sh to automatically create simlinks, fill my /etc/hosts, set style and others.

I started with vimrc, now my configuration includes ssh, zsh, alias, hosts and it keeps growing.

This keeps my machines synchronized easily.

1

u/lannisterstark Nov 09 '20

Do you have a guide on how to do this?

→ More replies (2)

8

u/[deleted] Oct 17 '20

Interesting. I've taken the idea of having a repo with config files from the multiple "dotfiles" found on github, but having symlinks would solve (for me) the fact that if I need a change I have to modify two configuration files (repo and system).

Thanks for the tip.

4

u/lyingriotman Oct 17 '20

So move all config files to one place (i.e /root/config/), and then put symlinks in the original location. So /etc/wireguard would be a symlink to /root/config/wireguard?

3

u/[deleted] Oct 17 '20

You got it.

19

u/Bubbagump210 Oct 17 '20

My best Linux Pro Tip (LPT) is read and reread your commands before hitting enter lest you have LTP errors and really break something.

2

u/ErebusBat Oct 17 '20

Oh how does this not have more upvotes!

1

u/Aberry9036 Oct 18 '20

And again, and again, and again. Also, that sexy only-fits-on-an-ultrawide one liner bash command really does deserve it's own bash script, and once you've broken it down to its constituent steps you'll find a fuckup in it somewhere.

38

u/rustilyne Oct 17 '20

shouldn't Linux Pro Tip LPT?

13

u/Smaug_the_Tremendous Oct 17 '20

The real lpt is always in the comments

→ More replies (1)

8

u/pailanderCO Oct 17 '20

That was what I thought....

31

u/breakbeats573 Oct 17 '20

Don’t add random PPAs to your package manager. Not only can it cause conflicts, it can also be a security risk. Investigate before you add repositories.

7

u/smog_alado Oct 17 '20

These days I use flatpaks for a most of the stuff I used to use 3rd party repos for in the past. Avoids all the trouble with the depencency conflicts.

12

u/nongaussian Oct 17 '20 edited Oct 18 '20

This. I am a longtime Linux user ( started with Mandrake in early 2000s), and I install programs three ways:

  1. Package manager from the official repos

  2. Git clone+make+sudo make install to /usr/local or to ~/bin

  3. However the commercial package (Insync, Dropbox...) wants me to

2 might sometimes force me to have PPAs for some libraries, but I generally prefer compiling my own apps over PPAs.

7

u/Atralb Oct 18 '20 edited Oct 18 '20

This is nonsense. The 2) option is worse on all counts. Security, package management, dependency linking for traceability, etc...

If you verify the source on a git repo, then you can also verify the source the PPA points to, so why are you only complaining for the ppa ?

→ More replies (3)

3

u/fw2ty Oct 17 '20

4) Flatpak!

1

u/[deleted] Oct 17 '20

I used to run Mint and loved it, but my software wants involved adding a lot of PPAs. They were trustworthy sources, but you pay a price for just having them in update speed. My package manager going through every PPA and checking for changes slowed down updates immensely.

I run Arch now so I could get the bulk of my software from official repos, and everything else from the AUR after doing the appropriate security checks.

1

u/funbike Oct 18 '20

Good advice. I switched to rolling release distros with more modern packages so I don't have to use things like PPAs as much.

15

u/ctm-8400 Oct 17 '20

Learn awk.

5

u/zardwiz Oct 17 '20

Day one of learning *nix: Why would I ever?

Day fifteen: Wow, ls -lhtZA sure dumps a bunch of data in this directory with 15k files. “More” just isn’t cutting it, wish I could easily split these col....

Oh wait. Now I get it!

Seriously tho there are four or five basic utilities that have saved my tail a few times. Sed is also on that list, if for no reason other than reducing log noise.

4

u/imakesawdust Oct 17 '20

I learned decades ago that skillful use of awk, find and grep can make up for lack of knowledge of a lot other unix commands. Throw basic sed regex skills in the mix and you have a pretty usable toolbox.

13

u/Disruption0 Oct 17 '20

Explore /var/log It will be THE place !

5

u/TundraGon Oct 17 '20

sudo tail -f /var/log/messages

It's like watching life. ( It givea a live output of the file as it is written )

2

u/AreTheseMyFeet Oct 18 '20

I also always tail -n 50 -f <file> to include the last 50 lines of the file/logs as well.

13

u/jzbor Oct 17 '20 edited Oct 17 '20

If you are using a pacman based distro create some hooks that clean up your cache, whenever something gets removed/updated. Otherwise you'll end up with a lot of wasted space on your partition - especially when you use it for some years and regularly install new packages and remove other ones.

EDIT: Made a github gist for it

4

u/remenic Oct 17 '20

It's always wise to keep a copy of the previous version around in case the latest update breaks something. Happened to me a few times.

7

u/jzbor Oct 17 '20

Yes you're right! For example paccache -rk2 to keep the last two versions.

EDIT: Btw for the removed ones: paccache -ruk0

3

u/remenic Oct 17 '20

I have to confess, I didn't even know about that command! Thanks for the tip.

4

u/jzbor Oct 17 '20

You can just add these files so it cleans your cache automatically when pacman runs...

13

u/bog_deavil13 Oct 17 '20

Use timeshift and create full snapshot backups of your system so it can be restored after a fuckup

5

u/CGA1 Oct 17 '20

This has saved my butt on more than one occasion.

2

u/MrWm Oct 18 '20

I just killed my home folder with timeshift rm. not fun.


Just a word of warning for people: if you don't like timeshift and uninstall it, make sure to double check what you are deleting. I ran sudo find / -type d *ime*ift* and then found that timeshift left a directory called /run/timeshift. My stupid brain thought that it would be okay to sudo rm -rf /run/timeshift without double checking it and I ended up nuking my /home/ directory.

Lesson learned.

13

u/supradave Oct 17 '20

Backups. Seriously. Even today, someone that has nearly 30 years experience did rm -rf /wrong/spot and felt really stupid afterwards. But since I have a backup, /wrong/spot was easily recoverable.

Disk space is cheap or online is cheap. There are no excuses.

13

u/[deleted] Oct 17 '20
  1. Put /home on a separate partition.

  2. Learn to use git and put your dotfiles into version control.

  3. Learn to use man and info to learn how to use your applications.

  4. Learn the shell. It will allow you to do many operations faster than you might with a GUI app, and knowing how to write your own shell scripts will let you automate repetitive operations.

  5. If you're in a terminal window and you accidentally hit CTLR+S, hit CTRL+Q to unlock the terminal.

  6. Once you've gotten the hang of shell scripting, you can schedule jobs using cron.

  7. Disable root login in /etc/sshd. That will make life harder for script kiddies trying to bruteforce your machines.

8

u/Phydoux Oct 17 '20

Disable root login in /etc/sshd

On my system it's /etc/ssh/sshd_config

6

u/Phydoux Oct 17 '20

I'll take your first tip one step further. Put the /home on a separate hard drive altogether. Drives are cheap. My /home folder resides on a 3TB drive. The rest of the system is on a 750GB drive. I paid about $100 for that 3TB drive and it was the best investment I ever made so far.

1

u/[deleted] Oct 18 '20

I agree. As long as you've got room in the computer for a second drive, by all means put /home on a separate device.

12

u/[deleted] Oct 17 '20

git is your friend, and can be used for more than just source code. For example, putting /etc in git can help you roll back to previous configurations. Just be careful about the visibility of any remote servers you use.

11

u/U5efull Oct 17 '20

when trying to find out what process number a particular program is using so I can kill it (very helpful when troubleshooting a frozen steam proton session):

ps aux | grep <name of program>

example:

ps aux | grep Counter

4

u/cdp1337 Oct 17 '20
ps aux | grep wine
kill 15454
kill -9 15454
sudo kill -9 15454
sudo reboot

My usual use and progression of ps aux.

3

u/smog_alado Oct 17 '20

I prefer doing this kind of thing interactively from inside htop. Use the search feature to filter the list of processes and then use F9 to kill it if necessary.

5

u/U5efull Oct 17 '20

you can do this, but it's just the way I do it.

that's the beauty of Linux, there are many ways to do the same thing

2

u/smog_alado Oct 17 '20

Absolutely

3

u/[deleted] Oct 17 '20
alias psa='ps aux | grep'
echo !! >> ~/.bashrc

2

u/AreTheseMyFeet Oct 18 '20

echo !! >> ~/.bashrc
Safety note to beginners, this second command is to copy the LAST EXECUTED command in to your user bash config so it can be available across sessions.

In this specific case if you run these two commands in turn you will have an alias added to your config but if you run anything else before the second command THAT command will be executed EVERY TIME you start a new shell session.

3

u/team_broccoli Oct 17 '20

killall programname

does the same in most usage cases?

0

u/[deleted] Oct 17 '20

[deleted]

4

u/U5efull Oct 17 '20

perhaps my pgrep works differently, but it does not give the same results

0

u/[deleted] Oct 17 '20

[deleted]

3

u/U5efull Oct 17 '20

I guess I just got used to doing it with the | and grep and never looked back. The thing is, splitting the command out taught me a bit about grep and I started using it for other things as well, so it's a good technique to learn and build on.

4

u/[deleted] Oct 17 '20

I always forget that this exists. Thanks for the reminder!

10

u/kaerock Oct 17 '20

Learn your basic shell command navigation. Far too often I see people doing so much typing for something simple. Bash has tons of helpful built-in shortcuts. For example:

To find a command from your command history in bash to re-run it or modify it and re-run it:

Control+R <command history pattern>

Skip to beginning of line: Control-A

Skip to end of line: Control+E

Erase everything to right of the cursor: Control+K

Erase everything to the left of the cursor: Control+U

Command/filename completion: Tab key.

Get these down and your work flow will be way more efficient.

Also, spend time in vi/vim. Get to know your tools so when you use them you're not fumbling around when you're trying to accomplish something else.

1

u/AreTheseMyFeet Oct 18 '20

On navigation, a pair of convenient shorthands I use multiple times per hr:

alias ..='cd ..'
alias ...''cd ../..'

9

u/pasmon Oct 17 '20

If you live in terminal, install fzf: https://github.com/junegunn/fzf

8

u/amberoze Oct 17 '20

Best advice I ever got.

Break it.

If you want to learn Linux, break it, then fix it. It's not practical, but it worked for me.

2

u/zardwiz Oct 17 '20

Currently giving a junior the abbreviated tour of everything from the kernel up. For the $25 monthly cost, a sandbox they can break might be the best ROI on training dollars we’ve ever spent.

1

u/amberoze Oct 18 '20

Either a sandbox VM, or a spare workstation. The other bonus is, you can break it, then let the trainee fix it.

1

u/gjch Oct 18 '20

That's a lot to pay monthly for a Linux sandbox. Why not a $5/month box from Linode (or similar) or a one-time payment for a Raspberry Pi?

→ More replies (1)

21

u/bionade24 Oct 17 '20

Use btrfs. With a root, a home and a snapshots subvolume, created on the same level (Don't use the btrfs rootvolume for root but a subvolume). Mount snapshot under /.snapshots and configure snapper to do hourly backups of root and home. If you don't do that, you'll regret it 1000 times.

MAKE BACKUPS!!!!

5

u/[deleted] Oct 17 '20

And never ever confuse snapshots with backups :)

9

u/[deleted] Oct 17 '20 edited Jun 01 '24

crowd wise history capable run icky bedroom lock afterthought smart

This post was mass deleted and anonymized with Redact

4

u/spryfigure Oct 17 '20

If you use btrfs, use a btrfs-friendly distro like OpenSUSE.

Or at least use their subvolume layout. It's made for a reason, and the reason is that you have more trouble with btrfs if you don't. Things like btrfs being full even it's not full. Or worse.

7

u/Lindby Oct 17 '20

I see the hd of my computer as a local cache. If the data hasn't been pushed elsewhere, it is not persisted.

3

u/ErebusBat Oct 17 '20

Yes! 1 copy of a thing is 0 copies.

Also for critical data remember the 3-2-1 rule:

At least 3 copies. On at least 2 different mediums. At least 1 copy off-site.

2

u/bionade24 Oct 17 '20

Have to remember that to tell this to people loading their images from smartphone to laptop.

3

u/TheTechRobo Oct 17 '20

I've heard bad things about BTRFS. Here is an example: https://forum.elivelinux.org/t/how-to-recover-from-a-btrfs-crash-failure/1206

4

u/bionade24 Oct 17 '20

That's the revenge of RTFM. People using discard as mounting option despite there are warnings everywhere.

2

u/ErebusBat Oct 17 '20

Really? The wiki doesn’t seem to indicate not to use it... just that it could add some performance on some ssd

https://btrfs.wiki.kernel.org/index.php/FAQ#Does_Btrfs_support_TRIM.2Fdiscard.3F

2

u/wired-one Oct 17 '20

Preference is to use trim timer in the OS

3

u/ErebusBat Oct 17 '20

Yeah... the the comment I replied to implied that the user messed up by enabling discard when it was plain that was bad advice. I was pointing out that the docs don’t (at least now) communicate that.

1

u/[deleted] Oct 17 '20

That was over a year ago, I would think things have improved since then.

0

u/[deleted] Oct 17 '20

[deleted]

8

u/spryfigure Oct 17 '20

Not for btrfs. ( ͡~ ͜ʖ ͡°)

4

u/bionade24 Oct 17 '20

I guess it's a meme now.

7

u/bionade24 Oct 17 '20

Hourly backups? Excessive I think

That are incremental Snapshots on a CoW Filesystem. Doesn't make any noticeable overhead. And when you had informed yourself about snapper, you would know that you can configure snapper to only store one `n` snapshot(s) per hour/day/week/month/year, rest gets deleted after the time area ended.

6

u/jess-sch Oct 17 '20

So this one's more for GPG: Use a YubiKey 5. Seriously, those things are just great for key storage. Also, use Curve25519. And require touch so no application quietly uses your key in the background.

That said: Don't use Curve25519 if you need it to work on Android too, since OpenKeychain crashes if you use anything other than plain old RSA.

6

u/smog_alado Oct 17 '20 edited Oct 17 '20

One neat trick I like doing is if you want to watch a long video from youtube or similar website, try playing through a video player such as mpv instead of via a web browser. That way you get more control over the playback speed and as well as seeking forwards and backwards. Also helpful if you have a weak computer that strugles to play videos via the browser.

As a time saver, I have a small script that grabs a video URL from the clipboard (using wl-copy or xsel), shows a dialog using zenity to choose a resolution and then calls mpv with the appropriate flags.

3

u/Fearless_Process Oct 17 '20

This is really great if you have a low end computer or an old laptop. Videos in the browser were completely unusable for me on one of my old laptops, but mpv would play them with ease. It also helps the computer to not overheat and kill the battery as fast.

6

u/redditorrium Oct 17 '20

Know how to exit vim.

15

u/gjch Oct 17 '20

I was once stuck in vim for 4 1/2 months. I ended up just buying a new computer.

6

u/balanaicker Oct 17 '20

learn a little about systemd. Most of the software and hardware could be restarted, debugged and configured easily if you know how to use systemctl and journalctl.

→ More replies (1)

6

u/BloodyIron Oct 17 '20

Linux Pro Tip would be LPT, LTP is Linux Tip Pro.

6

u/TundraGon Oct 17 '20

ssh -t [email protected] 'sudo tail -f /var/log/messages for a live output into your terminal.

I find it much easier than directly ssh into the machine.

5

u/[deleted] Oct 17 '20

When you need to do stuff you often find articles or tutorials solving your current problem. Don't blindly copy and paste commands into your terminal. Try to understand what each line does and why is it needed.

Many tutorials are unnecessary complex, stupid or plain wrong. Not to mention, it's a security flaw to mindlessly copying unknown commands. Especially those run as root.

5

u/t0mm4n Oct 17 '20

Use sshfs. Its easiest way to do network mount. It is also secure.

5

u/t0mm4n Oct 17 '20

Use rsync. My first choice for file transfer locally and over net. It is also great for backups.

5

u/ibraheemMmoosa Oct 18 '20

Set HISTTIMEFORMAT to "%d/%m/%y %T "(or any other date time format you prefer) in bashrc and also set HISTFILESIZE and HISTSIZE to -1 in bashrc and have infinite bash history with date and time of each command.

2

u/pnht Oct 18 '20

I use this. Didn't know about -1

HISTCONTROL=
HISTSIZE=1000000
HISTFILESIZE=1000000
HISTTIMEFORMAT='%F %T - '
HISTFILE="$HOME/.bash_history"

shopt -s histappend
shopt -s histreedit
shopt -s histverify
shopt -s cmdhist
@2020-10-18 03:15:59 wwalker@polonium:~ ✓ $ history | wc -l
255605
@2020-10-18 03:16:13 wwalker@polonium:~ ✓ $

5

u/1Teddy2Bear3Gaming Oct 18 '20

Don’t run a command unless you understand what it is and what it does. Make frequent backups. You shouldn’t need to use command line very much on most mainstream distros.

4

u/LittleSeneca Oct 17 '20

Be careful what you type into the shell! Sl is more fun than ls, but ls is more useful. Likewise, rm -rf * is fast, but rm -rf /move/to/specific/directory reduces the chances you're going to blow up your computer.

4

u/JackDostoevsky Oct 17 '20

in bash, !! is a stand-in for the last command run in your console.

so let's say you just ran a big update command (pacman -S something somethingelse somethingmore), but you didn't sudo.

instead of re-typing or even copy-pasting your last command, you can just follow up with:

sudo !!

and it'll sudo your last command.

4

u/Disruption0 Oct 17 '20

Or :

up or Ctrl + r (expression) Ctrl + a Type sudo.

I don't like the !! . I really need to see every command especially when it meets sudo privileges.

By the way nice pseudo.

4

u/M3tzg3r Oct 17 '20

Check if Magic SysRQ is enabled on your system so you can ALT+PrntScr+REISUB to recover from your locked up linux desktop or server. Saved my ass several times now, and my coworkers where baffled I did not have to hard reset.

4

u/cyber_rigger Oct 17 '20

install this:

dselect

If your desktop (graphic system) gets hosed in the middle of an update,

You can recover using this text-based package manager.

Dselect is 25 years old and fairly bullet-proof.

4

u/i_likebeefjerky Oct 17 '20

Ctrl + r Now start typing a previous command. It recursively searches your command history.

10

u/impune_pl Oct 17 '20

#1 Git gud with git.

It's very powerful tool, not only for programming projects, but also for documents and config files.

#2 If you can spare a few minutes and read manual or help of a tool to find out how to use it instead of googling it.

It will take more time, but you will remember it better. You will also learn more about the tool.

#3 Learn the basis of vim or emacs.

Personally i prefer vim, but both are very powerful editors. By basis i don't mean 'memorize vimtutor' but get familiar enough with it to feel comfortable using it (instead of, for example, gedit) for editing files.

6

u/figthedevil Oct 17 '20

Tab auto-completion is your friend! Saves you so much time when giving commands, especially when navigating through the filesystem.

3

u/ipsirc Oct 17 '20 edited Oct 17 '20

rootfs on zstd compressed ramdisk - not easier, not secure and not nicer, just faster.
│26│252:0│/dev/zram0│ext2 │6.8G│4.9G│ 73%│ 1.8G│/ │

3

u/[deleted] Oct 17 '20

Could you please guide me to more information on that? All I found are feature requests, very short descriptions of zstd and unrelated pages. Are any of the big distributions using this? Is it very new and not implemented yet in most distributions?

4

u/Fearless_Process Oct 17 '20

Zram and zstd are used quite a lot. I know android uses zram for example, and some other distros have and probably still do. I have used it for as long as I have known about it.

Most people use zram as a swap device. The zram device is a space allocated in your memory that gets compressed on the fly, which makes you be able to store more stuff in it. You can also use zram devices just like you would use any other block device, you can make a tmpfs in it and mount it somewhere. I've never heard of someone putting root on it though, not sure how that would be done.

2

u/ipsirc Oct 18 '20

I made 2 shellscripts: One runs at system shutdown(reboot) - backup all files to a .tar file. The other runs from initrd - create zram, put ext2 on it then extract the .tar file.

Not as complicated as you think. The cause why distributions are not implented it by default is you can lost all your new data since the last backup, if your system hangs or get power outage.

→ More replies (2)

3

u/misterph3r Oct 17 '20

Tab completion in cli. I run into people I mentor that don’t know about it months into their first experiences with cli.

I didn’t learn about tab complete until a year after I started my career, and it was on accident.

3

u/Config_Crawler Oct 17 '20

Learn the basics of bash scripting. Saves me tons of time doing repetitive things.

3

u/[deleted] Oct 17 '20

don't look up stuff everytime something doesn't work, check the documentation.

Also install your own system and your software. This way you will know where to look when things break.

3

u/GitProphet Oct 17 '20

Create a file of all those weird shell commands that fix your problems. e.g. github.com/SimonLammer/dotfiles

3

u/TundraGon Oct 17 '20 edited Oct 17 '20

vi or vim

All you need to learn is to ( just press on keyboard )

  • INSERT by pressing i

  • Press the ESC kry to leave INSERT mode then:

  • Save and close :wq

  • No save and close :!q

You will need to login remotely into some machines and you cannot install anything. vi comes installed by default.

1

u/pnht Oct 18 '20

vimtutor - 30 minutes and you'll know enough for vim to already be more productive than whatever editor it is replacing for you. :-)

1

u/SnooSquirrels8869 Oct 19 '20

As a heads up, on Vim (not sure about Vi), :x does the same thing as :wq so you can save yourself exactly one keystroke :)

3

u/Aberry9036 Oct 18 '20

My LPT is buy a raspberry pi and pick a headless distro to install, then go to town running as many services on it as you can think of. My venerable little pi runs Ubuntu server 20.04, a gitea server with webhooks to rebuild and restart a local docker container on a merge to master, a dhcp, dns and dns-over-ssl server, a WiFi access point powerful enough to stream VR over, a wireguard server, a dynamic dns client and a webserver over all of my web apps with let's encrypt, including a reverse proxy to a few apps running on my desktop. And it doesn't even break a sweat.

Without a desktop, you come to realise how truly powerful and lightweight Linux really is, and a pi is an inexpensive and forgiving playground to learn on.

10

u/LinuxChromebookDude Oct 17 '20

use a window manager. it boosts your productivity and makes multitasking easy. as a full time software developer I find this easy, but there are easy ones like i3 or openbox.

13

u/bionade24 Oct 17 '20

You mean don't use a full DE. X11 nearly always is used with an Window manager.

5

u/sandelinos Oct 17 '20

Well if you didn't use a window manager multitasking would be pretty hard wouldn't it.

4

u/bionade24 Oct 17 '20

You could write something that uses bitwise `&` to show the color of one pixel of all programs open.

7

u/jwaspin Oct 17 '20

Does tmux qualify as a window manager?

4

u/spryfigure Oct 17 '20

It's the best window manager.

2

u/johnisom Oct 17 '20

Yes, it’s a terminal based window manager instead of a graphical one

3

u/vetu11 Oct 17 '20

I am currently using the Material Shell of Gnome and I never thought things wm like this would be for me, but I'm loving it

4

u/[deleted] Oct 17 '20

Material shell (or pop-shell as I used the pop os version) was a bit glitchy for me, windows overlapping and not auto-resizing. It's a great idea, bringing the productivity of tiling to a full DE, but just not quite there yet. Plus you have all the bloat and massive resource usage of gnome. Personally I get on much better with traditional tiling WM's

2

u/[deleted] Oct 17 '20

I really recommend you try out just a window manager. Material shell, and gnome in general, is resource intensive and not very customizable at all. I recommend you try i3wm, awesomewm, and spectrwm.

→ More replies (1)

1

u/[deleted] Oct 17 '20

instantWM is also pretty good and it is also noob friendly. It comes with InstantOS.

2

u/smog_alado Oct 17 '20 edited Oct 17 '20

If you are installing Debian, leave the root password blank when you get to the part of the installer that asks for a root password. This way you can use sudo on your main account.

2

u/shanlar Oct 17 '20

ansible your workstation and use nextcloud for files you care about. then you have the freedom to reformat monthly if you want, without the headache of setting everything back up.

i have a pxe entry for installing and configuring my workstation from fresh. any app i care to keep around gets committed to ansible, if not it's gone on my next refresh.

2

u/zoharel Oct 18 '20

Honestly, just use the directory stack. Every shell worth anything these days has pushd and popd commands, and it's a whole lot easier to pushd something and popd when you're done than it is to note your current location, cd somewhere else, and then cd back to wherever you were. It's a highly underappreciated feature.

2

u/[deleted] Oct 18 '20 edited Oct 19 '20

Also, when you're hopping between two directories, cd - is pretty useful.

2

u/ccAbstraction Oct 18 '20

If it's desktop Linux, remember that everything you'd consider to be a part of the operating system is more or less just an app that happens to work well with the other apps that came with your distro. Lots of times it's better to search for help with that specific app rather than your distro. Like don't search for how do something in Ubuntu or Manjaro, but rather Nautilus or PCManFM.

3

u/[deleted] Oct 17 '20

Can you explain about the temporary folder? Does it auto delete old stuff or something like that?

3

u/TriumphRid3r Oct 17 '20 edited Oct 19 '20

I do just like OP and no, nothing is auto-deleted. That said, you could always write a cronjob using find to delete anything older than x days if you so desired. A cronjob in /etc/cron.d might look like below.

0 0 * * * user find ~user/tmp -mtime +60 -execdir rm -v {} +

For me though, I go through ~/tmp periodically & delete old files I know I no longer need.

Edit: fixed crontab timing

3

u/[deleted] Oct 17 '20

Thanks for the command. I was planning to do something similar, do you saved me the research. I asked the question too the OP because that's not very Linux specific. I do the same on Windows too, so I thought there was something more to it.

2

u/make_onions_cry Oct 19 '20

Note that this does not run daily, but actually 60 times per day.

1

u/TriumphRid3r Oct 19 '20

You're right. I've edited the crontab timing in my post.

2

u/everymoderatorisbad Oct 18 '20

The only thing worse than Ubuntu is its forum support.

Use Debian.

1

u/linofex_ Oct 18 '20

I am working on a project with many source files. I often search string errors and prints by tipyng grep -irl "string_to_search" ./ (where ./ is the root project directory or an inner directory where I assume the file is)

1

u/sharkcathedral Oct 18 '20

I made a script called helpme that awks a help file that I add all the helpful commands I pick up that are a little too elaborate for me to remember. Then when you are in a bind you just type "helpme samba" or whatever and it prints out all the commands I have in that section.

1

u/SBelwas Oct 18 '20

On the terminal, ctrl+r will start at command history search that will autocomplete the most recent matching command in your history.

1

u/funbike Oct 18 '20

I prefer pandoc markdown over Office products (e.g. LibreOffice).

I write everything in markdown and when I want to share I use Pandoc to convert to docx, pptx, or pdf. I also have a script that converts markdown in my clipboard to rich text for pasting.

When people send me .docx or .pptx files, I convert them to pdf. soffice --headless --convert-to-pdf file.pdf

I can manage my documents' versions with git and share them with github.

I use pandoc filters for various enhancements (graphviz, gnp plot, plantuml, csv) and I embed LaTeX when markdown isn't enough.

1

u/ThellraAK Oct 18 '20

Be prepared to reinstall:

Have a live disk ready to rescue or reinstall your linux installation if you fuck it up.

Have backups ready so you don't have to sit in a live environment and backup anything you still want.

Keep a list of any workarounds you needed to get things working the way you wanted.

1

u/bruce3434 Oct 18 '20

What is your best Linux Pro Tip?

Avoid Nvidia.

1

u/APimpNamedAPimpNamed Oct 18 '20

There is a snap available for running C&C Red Alert 2 Yuri’s Revenge on almost any distro. Works flawlessly and supports 1920X1080.

0

u/team_broccoli Oct 17 '20

Tired of having to type sudo before every command?

Give yourself some root privileges with sudo su

Type exit when your'e done screwing up your system.

5

u/Mar2ck Oct 18 '20

sudo -i is the preferred way of doing this