I am a 78 yr old retired field tech from a Mirosoft and Novell background. With Microsoft shenanigans, I decided to move to Linux, it's been a steep learning curve but I enjoy it. This is the first time I've seen one of your vids. I think its great that you are teaching these tricks! Thank you so much. I'll be subscribing.
Scotty, same here with the Windows requirements. My boy's laptop has been running KDE Neon for 2 years now with no issue. I just moved the work laptop to KDE as a test with their new release. The 3-4 work PCs get moved in 6 months. We are web devs so most of our stuff is out in the cloud already. Libre Office, GIMP, Bootstrap Studio are our desktop apps. I tested many distros and KDE Neon, built on Ubuntu, is beautiful, solid and fast. One of the old work/test PCs is a dual core, 2GB of memory and runs Neon just fine.
@@patrickvanrinsvelt4466 Thanks for the tip re Boostrap Studio. As I'm more of a back-end developer this is great for doing a quick front-end without having to become an expert on the front-end.
summary of the commands: 1. `cd -` : back to the last directory we've been to. 2. `ctrl+l`: clear screen 3. `reset`: clear on steroids - resets terminal session 4. `pushd /var` + few other `cd` commands + `popd`: commands that allow you to work with directory stack and change the current working directory 5. `vim /etc/ssh/sshd_config` + ctrl+fz : isn't closing, but minimizing the window to the back ground `fg` : bring back the window to the front. 6. `apt update`: would fail - cuz we fogot sudo `sudo !!` : would run the last command as sudo 7. 8. run command that already been run - `history`, choose a number of command and run it `!102` -> the 102 command from the history would run again 9.HISTTIMEFORMAT="%Y-%m-%d %T" `history` would should the history commands by the format. another way to add the format, is add it to the `~/.bashrc` file with `vim` or `nano` commands. 10.cmatrix -> let you look cool + ctrl c to escape 11.adjust font `shift +` or `shift -`, `reset` command would reset the font size 12. `ctrl a` - start of the line `ctrl e` - end of the line 13.chainning commands -> `ls -l; echo "hello" ` or -> `ls -l && echo "hello" ` && - would stop when meets an error ; - would pop up an error and keep on running the second/next command 14. `tail` / `head` commands to see top or bottom of a file. 15. truncate (be cautious while using this one - its risky) it allows to change the size of a very large files (like log files) for example `truncate -s ` == truncate -s 0 hello.txt to empty the hello.txt file 16. `mount | column -t` : make sure all the output shows in columns any verbose and messy command output would look better using `| column -t`
CTRL U does remove the text on the line, if you are at the end of the line. What it is actually doing is removing from your cursor to the BEGINNING of the line. If you are in the middle of the line, it will remove everything BEFORE the cursor. Also, if you are in the middle of the line and type CTRL K, it will remove everything from the cursor to the END of the line. If you do CTRL A CTRL K, it is the same as CTRL U as you are going to the beginning and removing text to the end of the line. truncate was a new command for me (I've used 'cat /dev/null > filetoempty') and I learned about column, too! Cool video!
7:50 after ctrl + Z, the process is frozen, but you can type “bg” to make it continue running in the background. I use this all the time when e.g. I start some NodeJS service interactively, to see the messages, and then ctrl + Z, bg, enter, to turn it into a background process (and you can even exit the shell and it’s fine, it will continue running).
Also after Ctrl-Z, the command "jobs" will list out all backgrounded jobs with an index value to the left of each. If you wanted to bring the backgrounded job with the index value of "2" to the foreground, you may do so with the command "fg 2".
"(and you can even exit the shell and it’s fine, it will continue running)" This is technically not true (in most cases). If your shell is killed, it will kill the process attached to it by SIGHUP. You can get around this by using 'disown' or 'nohup'.
I use the "watch" command a lot for ad hoc progress monitoring. Also, to get to the home directory you only need to type "cd" no need for "cd ~". Cheers!
Good stuff! I learned a couple things! Regarding history, one other trick I do all the time is to re-execute the last command starting with a certain string. For example, !sudo will execute the last command in the history that started with "sudo". If you're not sure what that command is and want to see it before you execute it, you can type : !sudo :p The :p means preview the command but don't actually execute it (but it will add it to the history as if you had executed that command). If it's what you wanted to do, you can then just type !! and it will execute that command. And another trick I do all the time because of my clumsy typing is to quickly fix a typo and execute the previous command in one step using the caret ^ symbol. For example, if I type : sudp some really long intricate command I will get the error that sudp does not exist - oops, I meant to type sudo. All I have to do is type : ^sudp^sudo and it will reissue my previous command, replacing the first instance of "sudp" with "sudo". If you wanted to be really lazy, you could also type : ^p^o and it just replaces the first occurrence of "p" with "o"
along with 'ctrl a' and 'ctrl e', I use 'alt b' and 'alt f' for jumping backward and forward by word. This always helps if I need to jump to the middle of a very long command. 'alt leftarrow' and 'alt rightarrow' works similarly tooo. Also by the way all the linux short cuts also works with youtube video as well. Try it :) j - takes you 10 seconds backwards k - pause l - takes you 10 seconds forwards uparrow and downarrow increases volume f - fullscreen c - captions on (if available) m - for mute there are many shortcuts for youtube as well.
I am not sure if this is my shell/terminal app config, but pressing Esc followed by Backspace deletes from cursor position until beginning of word. I use it extensively in combination with alt+b
One the subject of pushing things in the background with crtl+z, there is wonderful tool called "screen". It's a terminal session that always runs in the background once started, even when you logout of the system. You can simply detach and re-attach whenever you need. It's a relic of times when terminal connections were not super reliable, like over dial up. In case of a connection drop, one could just re-login, re-attach screen and continue as if nothing happened.
Thanks for another great video. One small side note, the "ctrl+u" will ((at least on my "Pop-OS 21-04")) indeed work as You demonstrated. How ever what it "really does" is "deletes" all the entered text to the left of the cursor. So if the cursor is "at the end" of the line it will indeed "delete the full line", but if the cursor instead is at the start it will do nothing. And of course if You have the cursor "somewhere in the middle" it will just "delete" the text to the left of the cursor Just thought I'd mention that (possibly petty) detail :) Best regards.
use tail -F instead of -f (same as --follow plus nice --retry) It makes tail reading consistent the file even though the file rotates and a new file (with the same name of course) has been created
Running a previous command is much easier when you can type the start of the command then press up/down arrow to find all matching commands. So just like MATLAB or other languages. This can be done by creating the file ".inputrc" in your home directory. Populate the file with the lines: " "\e[A":history-search-backward " and: " "\e[B":history-search-forward " - do ignore the outside quotes. Now after you restart the shell you will get up/down arrows that search your command history.
Very good video on the command line. I'm 75 and grew up with UNIX while working with Bell Labs and developing software using C. I've been to a number of Unix Administration schools while working at Western Electric including Unix Internals. Back then there was no GUI and it was all command line interface on the terminal. I still have vi highly ingrained in me and today only use Ubuntu Linux. I really enjoyed your video and picked up a lot of new tips and some that shucked the old cobwebs into remembering. Thanks for the very well done video.
Good video, lots of useful things here, only a few things I feel need pointing out/including along with similar topics. Not sure if this will have been said but where Ctrl+Z is being mentioned using the word "background" would be confusing terminology (this point will become clear very soon), Ctrl+Z as the terminal returns is stopping the process, `fg` will foreground it but typing `bg` will actually then allow it to remain running without its output being displayed, similar to running with `&` when initially running the command, thereby actually running in the background, background jobs will still be killed when the terminal is closed and can be viewed using the command `jobs -l` and resumed by running `fg %X` where X is the number listed in square brackets by `jobs -l`. I personally use this for copy operations I don't need to monitor but will take a couple of hours, whilst working on other things. Where && is used to mean run command only if success || can be used to run only if failure. `tail -f | grep ` also works on all systems I've used which can be very useful if you have busy log files and only certain things you want to see (or not see if you include the -v flag of grep).
I hate to say this but many of the tutorials out there, the folks talking are hard to understand. I know that sounds bad, but it's a real issue either way. I greatly appreciate that you are in depth and easy to listen/hear. Thank you very much.
I like to use ESC followed by . (period) This key combination will insert the last argument of the previous command at the cursor position. This is very useful when you've entered a long filename at the end of a command (which is common) and now you want to apply another command to that same file. You can keep pressing ESC, period to access the last argument of previous commands.
Nice video! There's some good stuff in here I've not seen, like logging timestamps for commands in the history. 6:14 "^Z doesn't work with nano, I don't know why" Yeah, this one hit me a few times on some systems. Turns out, nano actually intercepts it depending on the configuration. If you want it to work, you can run nano with the -z option, or you can add 'set suspend' to your ~/.nanorc file.
Gosh, a couple reminders here. Things I've learned but never used enough to remember. One thing I think you could have included in the last section (column) was holding ALT while click+dragging can allow you to highlight (and copy) just the contents of a single column or multiple columns (without highlighting the entire line). This trick has been a life saver for me when I have a bunch of columns and I don't want to spend 15 seconds writing out a command to extract just the one column.
"History | less" and the "!#" are a timesaver!!!! Can't forget "ctrl+c" or "ctrl+z" when stuck,.. lol Thank you for all the work and time you put into these videos!
on the last item of piping output into column -t, I find that very long lines of text that line wrap are confusing to read so I additionally pipe output into less -S where -S option turns off line wrapping. If producing text with embedded terminal escape codes for setting colors on text strings, then can use -R with less command as it will then interpret those escape codes and text will be displayed with intended colors applied. So this allows for making some rather spiffy output that draws attention to headers, use red for errors and green for success, etc
I haven't seen much on this channel so maybe you already covered this but mastering the 'screen' command is a must have skill if you are doing any remote work on linux systems. It just takes one DC during a long task to make you appreciate the value of running long tasks in a dedicated screen so that you don't have to start over.
I would throw in "tmux" as an option, too! It's a "modern" version of screen, but both allow you to do amazing things, above and beyond running tasks even when your connection is cut (which is the reason I was introduced to "screen" in the first place). Theoretically, I'd use tmux on my local machine and screen on a remote terminal, but in practice, I haven't done much remote work in recent years, so I mostly just use tmux.
Jay, many thanks for a wonderful set of tips. Like many I have a grab bag of commands that I have picked up the the years to make life easier. These 18 little gems are fantastic. Many thanks. My favourite is CTRL Z and then return with fg. The number of times I have been in vi and need to quickly jump out and in, sometimes I'm to lazy to start another terminal session, this little trick solves that problem.
cd - and column are game changers thanks for sharing Another one I like which isn't mentioned here is the alias command (written into the .rc file for persistence is a huge time saver for example alias dist-update="sudo apt update && sudo apt upgrade-distro" Will run those commands every time you type dist-update into the terminal
I use curly brackets a lot, they allow for neat rename and other things. mv my_{first,second} And it will rename my_first to my_second. To understand a command expansion better, prepend the line with echo, and add more to the brackets, to see what happened before the line was executed.
Love these tips! Adding to your Ctrl + shortcuts, I often use Ctrl + W to erase the whole "word" left of the cursor. (Delimiters for what counts as a "word" is set in a file, I forget where; also affects what gets selected when you double-click on text.) After many years fooling around / learning in bash, I only recently started putting those ".." to good use, to backup and reenter a path tree at a different point. e.g. I'm in /etc/ssl/certs and want to get to /etc/snmp I used to type 'cd ..' 'cd ..' 'cd snmp' But now just use 'cd ../../snmp'
I don't know how useful it would be everyone, but one of the CLI tricks I do is install lsd (ls deluxe) and then alias ls to lsd in my shell's rc which which replaces ls to lsd. This gives me a more colorful listing output than the default ls command. I find it useful for times when I'm in the middle of project and it's late at night and I'm tired and hungry and that's when seeing the traditional output all starts to blur together from fatigue. The lsd output is in the same format as traditional ls, but has more color coding and if you have the right fonts enabled, will display little icons for the files and directories right withing the terminal session for you. It helps me out when things blurring together and it also looks cool so it's something I recommend people look at as they learn the terminal a bit more.
Not sure whether someone else mentioned that, but instead of tail -f I use less and press Shift-f to follow a file for some time. If something jumps to my attention, I can Ctrl-Z out of the follow mode, and go back to that line. You can also search with / for some particular errors, and they will be highlighted in follow mode, or use &search-string to just show the matching lines for your regex search in there.
1) the " truncate" command to clean the content of a file is pointless. If you want to delete the content of a file you " could" do with echo "" > /file_path/filename, but you can even skip the echo command. Just issue "> /file_path/filename" without the echo works and its much faster. 2) Ok mentioning ctrl +a and ctrl +e , but actually the keys "home" and "end" on your keyboard actually do the same. ( i use those) 3) A command i really like but is quite unkonwn is "tac" ( is like cat in reverse), and it's a "cat" command that reads a file bottom-up. Its quite usefull then you want to read a log file without knowwing how many lines to include. as example: tac /var/log/messages | more you read the logs starting with the most recent line and you can keep going backwards until you find what you are looking for.
Came here to mention your #1 and #2. Faster than typing out "truncate." Bonus tip: When you're 5 servers deep in SSH sessions, use +D (on an empty line) instead of typing "exit" to end a session.
Along with your list Ctrl+A, Ctrl+E, Ctrl+U you could also add Ctrl+K (to delete the line from the cursor up to the end) which I personnally find useful.
Good video, don't know if anyone already pointed out that ctl+z doesn't send the process in three background but the process gets suspended, which means that it will not be scheduled any more, up till you execute fg or bg. The first command sends as your showed up the app to own again the stdin, stdout and stderr, while there other sends the command to the background, writing anyway to stdout and stderr.
I have two that I have found to be very useful. - If you have a large amount of work, and you just need it to go away you can type: exit - If you need to create a large amount of work for somebody else to get them off your back on why you are not doing anything you can SSH into a server and type: shutdown -h now
Nice, used the ; chaining two CMDs to see how my Memory and CPU is doing in a compact view # CMDs connected together to show how my CPU and Memory is currently doing ps -eo comm,pcpu --sort -pcpu | head -5; ps -eo comm,pmem --sort -pmem | head -5 I just added this to a .sh script so I can run it quickly when needed. Keep up the good work!
You may use aliases instead of scripts for this kind of stuff. Aliases are so underrated but it's by far what I use the most when I want a command to be accessed easily
Thanks. Didn't know about 'truncate'. I once had a problem with one huge log file, and I tried to simply delete it, but it didn't free space used by this file because it was used by program. I think, truncate command could help me in that case.
My favorite is using TAB to autocomplete whatever I started to type. This seems to work for any command and any argument to a command, no matter what command. I was surprised you did not mention this as if it would be common knowledge not worth mentioning. It was not for me and I've seen lots of water pass under bridges. Someone else commented about using TAB here but in such an obscure context that one might not notice it or realize what TAB will do. I would say I never fully type in any command or argument knowing full well a simple TAB press will complete what I started. This is particularly useful when dealing with directory names.
26:41 instead of "truncate", i used to with "cat > your_file_name" that replace existing text with new text input, but I leave it empty by pressing "ctrl+c", then the file is empty.
you can also chain commands by using || (pipes) and it will do the opposite of &&. It will run second command only if the first one failed. Another cool command line tool I use A LOT is "screen". Its a console windows manager that allows you have multiple consoles *running*, switch between, split screen and many more. Most cool about screen is that you can detach from it (ctrl+a D D), log out from system, log back in and attach back to it "screen -DR" and continue where you left.
I think of command && another as saying that they must both run successfully. command || another says that one or the other needs to be successful. It follows the same rules as in C and C++ regarding evaluation, where the second won't be executed unless necessary (i.e. in the && case, only if the first works, and in the second case, only if the first fails).
instead of using "tail -f filename" I like using "less filename" and then shift+F, to force feed and update output as the file being updated. The advantage is that if I see something I need to troubleshoot or to go up and search for a keyword that draw my attention, I can do so right away while inside the "less" command. Even better I can do "less filename" search for the keyword, then do "shift+f" and if the keyword does show up while its feeding the content to the screen it will be immediately highlighted .
Very nice. Bang colon number lets you access a numbered argument from the previous command. Bang asterisk repeats all the parameters from previous command.
hi ! does popd and pushd handle multiple reference because i use a similar method that allow me to do that . Using the syntax =$(pwd) after that you can do cd $>var_name> or other stuff like copying ... thank you so much for that "cd -" thing
Thanks, many good tips! I agree that You can go long way doing things inefficiently by routine. It is well worth taking time to learn an adequate set of tools for the job. Problem is that the possibilities available are sort of overwhelming, so tutorials like this are really valuable. 👍
First one and a half minute; using Linux as a programmer for work and already learned something great; was using pushd and popd for scenarios were now I will just use cd -, awesome. Tip for you: you don't need to type cd ~, just cd without argument also works.
Great overview indeed! Didn't know about column utility. Btw. Ctrl-U does only delete from cursor position to the left. Ctrl-K kills from cursor to the right...
I'm not sure if you mentioned this one cuz I kinda skipped that part. But just like `Ctrl + u` clears the prompt to the left of cursor, `Ctrl + k` does its reverse i.e. erases everything to the right of cursor :)
another useful shortcut is ctrl +right/left arrow . this will (mostly) tab back through the command by the word. EX: you typed a command like "while read file;do a=$(tr [A-Z] [a-z]) ;ehco "$a" >> newfile.txt < file.txt;done" note echo is misspelled, so you hit up arrow to bring the command back up, and hit ctrl+left arrow to go back and correct the spelling. ctrl+right moves one word to the right and ctrl+left goes left by one word. also the end key goes to the end of the line and the home key takes you to the beginning.
The downside to using HOME/END keys is needing to lift up your hands from the keyboard. It’s a small inconvenience but CTRL+A/E is a bit more comfortable. Also, home/end placement is not consistent across keyboards. Getting used to A/E will allow muscle memory to kick in, regardless of the keyboard you’re using.
a brief word about stopped jobs. If you have stopped jobs and try to exit the shell, or logout, the system will tell you there are stopped jobs and put you back in an interactive prompt. If you let the job run in the background (bg or &), it will kill the job when the parent shell ends, unless you detach the process. If you lose connection with stopped jobs, then that process becomes zombied. On systemd installations, 'journalctl -f' replaces tail -f /var/log/syslog One of the major strengths of linux and UNIX for that matter, is the piping | you can have some really wild commands going with putting in things like sed and awk, sort, cat, and a whole host of other commands. What is the longest pipeline (what I made up to describe the piping of commands, and not necessarily chained) you've ever created?
In adding timestamps to the history. Those who have edited the .bashrc file at 16:30, you guys need to run the following command after saving the file. source ~/.bashrc The above command will execute the .bashrc file and then after that, you can see the effect. @linode
`. ~/.bashrc` also does the same, just saying. For him, it's working cause he already had the variable set in his prompt. And in the next shell, it'll always get sourced. So, he might have forgot I guess
no mention of ctrl + w? I use ctrl + w a lot.. in routers/switches as well as whatever unix box I am in Ex: cat /etc/hosts ctrl + w will remove 'hosts' from the line..
column is a great tip. ive been using linux for years and i didnt known it. thanks. btw i really like you clean and clear style. its very easy to watch
Thanks a lot for sharing nice tricks. Some of my observations I thought will share here: Font size increase "Control Shift +" works with the plus button from row below the function key row in keyboard. "Control +" does not work with plus button from numeric pad. Command erase using "Control u" actually erases the characters from current position to the beginning.
Besides the `!!` substitution, there is also the `!*` substitution which substitutes everything after arg[0]. So for example if you just finished inspecting a file with `less /path/to/my/file` and decided to delete it, you can simply run `rm !*`. It's not as frequently useful, but when it is you'll be glad you know it.
In the same way, you can use this to play with the last command args : !* all args !^ the first arg !$ the last arg (I use this a lot..) !:2 the second arg !:2-$ the second to the last args echo hello youtube video echo !:2-3 # this is going to output youtube video
working with linux since ages... but there were a number of useful tricks here i never knew or could not be bothered with at the time. thanks for bringing this back to my attantion, in hindsight its a shame i never used so many of those little things before
Just a note here ctrl z doesn't put the process into the background it interrupts it, which pauses execution. If you want the process to run in the background you can type bg after interrupting with ctrl z. This allows the process to RUN in the background. fg will still retrieve it from the background.
I am a 78 yr old retired field tech from a Mirosoft and Novell background. With Microsoft shenanigans, I decided to move to Linux, it's been a steep learning curve but I enjoy it. This is the first time I've seen one of your vids. I think its great that you are teaching these tricks!
Thank you so much. I'll be subscribing.
You spot the right place to learn more about Linux!
🙏
Scotty, same here with the Windows requirements. My boy's laptop has been running KDE Neon for 2 years now with no issue. I just moved the work laptop to KDE as a test with their new release. The 3-4 work PCs get moved in 6 months. We are web devs so most of our stuff is out in the cloud already. Libre Office, GIMP, Bootstrap Studio are our desktop apps. I tested many distros and KDE Neon, built on Ubuntu, is beautiful, solid and fast. One of the old work/test PCs is a dual core, 2GB of memory and runs Neon just fine.
dont forget to check out his channel learnlinuxTV. I learned a lot myself and feel confident in using Linux now, which is great and fun
@@patrickvanrinsvelt4466 Thanks for the tip re Boostrap Studio. As I'm more of a back-end developer this is great for doing a quick front-end without having to become an expert on the front-end.
summary of the commands:
1. `cd -` : back to the last directory we've been to.
2. `ctrl+l`: clear screen
3. `reset`: clear on steroids - resets terminal session
4. `pushd /var` + few other `cd` commands + `popd`: commands that allow you to work with directory stack and change the current working directory
5. `vim /etc/ssh/sshd_config` + ctrl+fz : isn't closing, but minimizing the window to the back ground
`fg` : bring back the window to the front.
6. `apt update`: would fail - cuz we fogot sudo
`sudo !!` : would run the last command as sudo
7.
8. run command that already been run - `history`, choose a number of command
and run it `!102` -> the 102 command from the history would run again
9.HISTTIMEFORMAT="%Y-%m-%d %T"
`history` would should the history commands by the format.
another way to add the format, is add it to the `~/.bashrc` file with `vim` or `nano` commands.
10.cmatrix -> let you look cool + ctrl c to escape
11.adjust font `shift +` or `shift -`, `reset` command would reset the font size
12. `ctrl a` - start of the line
`ctrl e` - end of the line
13.chainning commands -> `ls -l; echo "hello" `
or -> `ls -l && echo "hello" `
&& - would stop when meets an error
; - would pop up an error and keep on running the second/next command
14. `tail` / `head` commands to see top or bottom of a file.
15. truncate (be cautious while using this one - its risky)
it allows to change the size of a very large files (like log files)
for example `truncate -s ` == truncate -s 0 hello.txt to empty the hello.txt file
16. `mount | column -t` : make sure all the output shows in columns
any verbose and messy command output would look better using `| column -t`
17: shut down and use the phone instead.
5. Not ctrl+fz, rather ctrl+z
Thanks for saving me the time
THIS must be a pinned comment
`ctrl u` to clear the current prompt line
25+ years of command line advanced usage but with your video I learned about column -t and the history time variable
CTRL U does remove the text on the line, if you are at the end of the line. What it is actually doing is removing from your cursor to the BEGINNING of the line. If you are in the middle of the line, it will remove everything BEFORE the cursor. Also, if you are in the middle of the line and type CTRL K, it will remove everything from the cursor to the END of the line. If you do CTRL A CTRL K, it is the same as CTRL U as you are going to the beginning and removing text to the end of the line.
truncate was a new command for me (I've used 'cat /dev/null > filetoempty')
and I learned about column, too!
Cool video!
7:50 after ctrl + Z, the process is frozen, but you can type “bg” to make it continue running in the background. I use this all the time when e.g. I start some NodeJS service interactively, to see the messages, and then ctrl + Z, bg, enter, to turn it into a background process (and you can even exit the shell and it’s fine, it will continue running).
This is really cool.
Also after Ctrl-Z, the command "jobs" will list out all backgrounded jobs with an index value to the left of each. If you wanted to bring the backgrounded job with the index value of "2" to the foreground, you may do so with the command "fg 2".
@@banjohead66 or with just "% 2"
"(and you can even exit the shell and it’s fine, it will continue running)" This is technically not true (in most cases). If your shell is killed, it will kill the process attached to it by SIGHUP. You can get around this by using 'disown' or 'nohup'.
THATS what bg does ?? oh man that's useful lmao
This just might be the single greatest video I've ever watched in RUclips.
I use the "watch" command a lot for ad hoc progress monitoring.
Also, to get to the home directory you only need to type "cd" no need for "cd ~".
Cheers!
Or just ~
@@jgm113 no
@@twice4846 YES
@Jack Warner Not right. Cd taskes you to the Home directory for current user.
'cd' instead of 'cd ~' might me a bashism, not sure
Good stuff! I learned a couple things!
Regarding history, one other trick I do all the time is to re-execute the last command starting with a certain string. For example, !sudo will execute the last command in the history that started with "sudo". If you're not sure what that command is and want to see it before you execute it, you can type : !sudo :p The :p means preview the command but don't actually execute it (but it will add it to the history as if you had executed that command). If it's what you wanted to do, you can then just type !! and it will execute that command.
And another trick I do all the time because of my clumsy typing is to quickly fix a typo and execute the previous command in one step using the caret ^ symbol. For example, if I type : sudp some really long intricate command
I will get the error that sudp does not exist - oops, I meant to type sudo. All I have to do is type : ^sudp^sudo and it will reissue my previous command, replacing the first instance of "sudp" with "sudo". If you wanted to be really lazy, you could also type : ^p^o and it just replaces the first occurrence of "p" with "o"
Wow! 👌
Is there a way to delete a line from the history file? i.e. "del !999" to remove line 999 from history
@@rakemup Good question, not that I know of.
@@rakemup `history -d linenumber` should do it if you’re in bash. In ZSH I believe you need to exit the shell and then edit it out of ~/.zsh_history.
@@rakemup @Geoff Ball but your del command will be printed in history if you use del!999
along with 'ctrl a' and 'ctrl e', I use 'alt b' and 'alt f' for jumping backward and forward by word. This always helps if I need to jump to the middle of a very long command.
'alt leftarrow' and 'alt rightarrow' works similarly tooo.
Also by the way all the linux short cuts also works with youtube video as well. Try it :)
j - takes you 10 seconds backwards
k - pause
l - takes you 10 seconds forwards
uparrow and downarrow increases volume
f - fullscreen
c - captions on (if available)
m - for mute
there are many shortcuts for youtube as well.
Or set your shell in vi mode by using "set -o vi" and then use most of vim's movement commands after pressing Esc.
Those are emacs shortcuts. They work everywhere.
I use ctrl-k ctrl-y kill/yank often
you can see each frame of the paused video by pressing < or > (actually these are comma and dot)
I am not sure if this is my shell/terminal app config, but pressing Esc followed by Backspace deletes from cursor position until beginning of word. I use it extensively in combination with alt+b
One the subject of pushing things in the background with crtl+z, there is wonderful tool called "screen". It's a terminal session that always runs in the background once started, even when you logout of the system. You can simply detach and re-attach whenever you need. It's a relic of times when terminal connections were not super reliable, like over dial up. In case of a connection drop, one could just re-login, re-attach screen and continue as if nothing happened.
tmux is another
I used to use “screen” to maintain a session of the BitchX irc client.
screen discont.. in redhat 8 :(
9
Thanks for another great video.
One small side note, the "ctrl+u" will ((at least on my "Pop-OS 21-04")) indeed work as You demonstrated.
How ever what it "really does" is "deletes" all the entered text to the left of the cursor.
So if the cursor is "at the end" of the line it will indeed "delete the full line", but if the cursor instead is at the start it will do nothing. And of course if You have the cursor "somewhere in the middle" it will just "delete" the text to the left of the cursor
Just thought I'd mention that (possibly petty) detail :)
Best regards.
Thanks 🙏 for the video. I learned 3 Linux commands from it.
pushd / popd / truncate
Ctrl + w delete word by word.
I just appreciate you record and upload this in 4k so the text is so crisp, this makes me happy.
use tail -F instead of -f (same as --follow plus nice --retry)
It makes tail reading consistent the file even though the file rotates and a new file (with the same name of course) has been created
try "less +F"
Running a previous command is much easier when you can type the start of the command then press up/down arrow to find all matching commands. So just like MATLAB or other languages. This can be done by creating the file ".inputrc" in your home directory. Populate the file with the lines: " "\e[A":history-search-backward " and: " "\e[B":history-search-forward " - do ignore the outside quotes. Now after you restart the shell you will get up/down arrows that search your command history.
I love you
Very good video on the command line. I'm 75 and grew up with UNIX while working with Bell Labs and developing software using C. I've been to a number of Unix Administration schools while working at Western Electric including Unix Internals. Back then there was no GUI and it was all command line interface on the terminal. I still have vi highly ingrained in me and today only use Ubuntu Linux. I really enjoyed your video and picked up a lot of new tips and some that shucked the old cobwebs into remembering. Thanks for the very well done video.
you simply have one of the most concise, eloquent and knowledge impacting channel. thank you, sir!
Good video, lots of useful things here, only a few things I feel need pointing out/including along with similar topics.
Not sure if this will have been said but where Ctrl+Z is being mentioned using the word "background" would be confusing terminology (this point will become clear very soon), Ctrl+Z as the terminal returns is stopping the process, `fg` will foreground it but typing `bg` will actually then allow it to remain running without its output being displayed, similar to running with `&` when initially running the command, thereby actually running in the background, background jobs will still be killed when the terminal is closed and can be viewed using the command `jobs -l` and resumed by running `fg %X` where X is the number listed in square brackets by `jobs -l`.
I personally use this for copy operations I don't need to monitor but will take a couple of hours, whilst working on other things.
Where && is used to mean run command only if success || can be used to run only if failure.
`tail -f | grep ` also works on all systems I've used which can be very useful if you have busy log files and only certain things you want to see (or not see if you include the -v flag of grep).
I hate to say this but many of the tutorials out there, the folks talking are hard to understand. I know that sounds bad, but it's a real issue either way. I greatly appreciate that you are in depth and easy to listen/hear. Thank you very much.
Great video! I have been using Linux for 3 years and come from a Windows admin background but this old dog still managed to learn some new tricks.
Ok, one minute in, and already the first tip blew my mind and made the video worth a like
I like to use ESC followed by . (period)
This key combination will insert the last argument of the previous command at the cursor position. This is very useful when you've entered a long filename at the end of a command (which is common) and now you want to apply another command to that same file.
You can keep pressing ESC, period to access the last argument of previous commands.
Alt + '.' does this too
You can use !$ for substituing the last argument of the previous command
Nice video! There's some good stuff in here I've not seen, like logging timestamps for commands in the history.
6:14 "^Z doesn't work with nano, I don't know why"
Yeah, this one hit me a few times on some systems. Turns out, nano actually intercepts it depending on the configuration.
If you want it to work, you can run nano with the -z option, or you can add 'set suspend' to your ~/.nanorc file.
Gosh, a couple reminders here. Things I've learned but never used enough to remember.
One thing I think you could have included in the last section (column) was holding ALT while click+dragging can allow you to highlight (and copy) just the contents of a single column or multiple columns (without highlighting the entire line). This trick has been a life saver for me when I have a bunch of columns and I don't want to spend 15 seconds writing out a command to extract just the one column.
Awesome content, like always. Thank you for not forgetting the beginners like me.
"History | less" and the "!#" are a timesaver!!!! Can't forget "ctrl+c" or "ctrl+z" when stuck,.. lol Thank you for all the work and time you put into these videos!
on the last item of piping output into column -t, I find that very long lines of text that line wrap are confusing to read so I additionally pipe output into less -S where -S option turns off line wrapping. If producing text with embedded terminal escape codes for setting colors on text strings, then can use -R with less command as it will then interpret those escape codes and text will be displayed with intended colors applied. So this allows for making some rather spiffy output that draws attention to headers, use red for errors and green for success, etc
I haven't seen much on this channel so maybe you already covered this but mastering the 'screen' command is a must have skill if you are doing any remote work on linux systems. It just takes one DC during a long task to make you appreciate the value of running long tasks in a dedicated screen so that you don't have to start over.
I would throw in "tmux" as an option, too! It's a "modern" version of screen, but both allow you to do amazing things, above and beyond running tasks even when your connection is cut (which is the reason I was introduced to "screen" in the first place).
Theoretically, I'd use tmux on my local machine and screen on a remote terminal, but in practice, I haven't done much remote work in recent years, so I mostly just use tmux.
Jay, many thanks for a wonderful set of tips. Like many I have a grab bag of commands that I have picked up the the years to make life easier. These 18 little gems are fantastic. Many thanks. My favourite is CTRL Z and then return with fg. The number of times I have been in vi and need to quickly jump out and in, sometimes I'm to lazy to start another terminal session, this little trick solves that problem.
Thank you Jay (+ Linode for sponsoring things). Love these things.
Actually a bit surprised at how much useful new stuff I got out of this, I've been a linux user for 10-11 years.Thanks.
cd - and column are game changers thanks for sharing
Another one I like which isn't mentioned here is the alias command (written into the .rc file for persistence is a huge time saver for example
alias dist-update="sudo apt update && sudo apt upgrade-distro"
Will run those commands every time you type dist-update into the terminal
One of the most illuminating vids I've seen for ages!
I use curly brackets a lot, they allow for neat rename and other things.
mv my_{first,second}
And it will rename my_first to my_second. To understand a command expansion better, prepend the line with echo, and add more to the brackets, to see what happened before the line was executed.
I haven't finished watching the video but I'm constantly exclaiming 'Ohh!' and 'Ahhh!'. Thank you.
Really great video. I knew a lot of the stuff from years ago, but you also still showed a few more things that I didn't even know was possible.
Thanks for doing this! I've been using Linux off and on for over 20 years and thought I knew my way around pretty well, and I learned a ton!
Love these tips!
Adding to your Ctrl + shortcuts, I often use Ctrl + W to erase the whole "word" left of the cursor.
(Delimiters for what counts as a "word" is set in a file, I forget where; also affects what gets selected when you double-click on text.)
After many years fooling around / learning in bash, I only recently started putting those ".." to good use, to backup and reenter a path tree at a different point.
e.g. I'm in /etc/ssl/certs and want to get to /etc/snmp
I used to type 'cd ..' 'cd ..' 'cd snmp'
But now just use 'cd ../../snmp'
I don't know how useful it would be everyone, but one of the CLI tricks I do is install lsd (ls deluxe) and then alias ls to lsd in my shell's rc which which replaces ls to lsd. This gives me a more colorful listing output than the default ls command. I find it useful for times when I'm in the middle of project and it's late at night and I'm tired and hungry and that's when seeing the traditional output all starts to blur together from fatigue. The lsd output is in the same format as traditional ls, but has more color coding and if you have the right fonts enabled, will display little icons for the files and directories right withing the terminal session for you. It helps me out when things blurring together and it also looks cool so it's something I recommend people look at as they learn the terminal a bit more.
I'll have to give it a look.
If you like "lsd" you'll might want to take a look at "exa". It's very similar but even more powerful, and it's in most distributions' repos.
@@ingokrispin3482 Thanks, I'm looking into it now! ;)
Not sure whether someone else mentioned that, but instead of tail -f I use less and press Shift-f to follow a file for some time. If something jumps to my attention, I can Ctrl-Z out of the follow mode, and go back to that line. You can also search with / for some particular errors, and they will be highlighted in follow mode, or use &search-string to just show the matching lines for your regex search in there.
As usual, great video for beginners. 👍!
Keep it up.
1) the " truncate" command to clean the content of a file is pointless. If you want to delete the content of a file you " could" do with echo "" > /file_path/filename, but you can even skip the echo command. Just issue "> /file_path/filename" without the echo works and its much faster.
2) Ok mentioning ctrl +a and ctrl +e , but actually the keys "home" and "end" on your keyboard actually do the same. ( i use those)
3) A command i really like but is quite unkonwn is "tac" ( is like cat in reverse), and it's a "cat" command that reads a file bottom-up. Its quite usefull then you want to read a log file without knowwing how many lines to include. as example:
tac /var/log/messages | more
you read the logs starting with the most recent line and you can keep going backwards until you find what you are looking for.
Came here to mention your #1 and #2. Faster than typing out "truncate." Bonus tip: When you're 5 servers deep in SSH sessions, use +D (on an empty line) instead of typing "exit" to end a session.
Along with your list Ctrl+A, Ctrl+E, Ctrl+U you could also add Ctrl+K (to delete the line from the cursor up to the end) which I personnally find useful.
Man.. I use Linux for last 20 years and I still found several new tricks! Awesome compilation!!
Good video, don't know if anyone already pointed out that ctl+z doesn't send the process in three background but the process gets suspended, which means that it will not be scheduled any more, up till you execute fg or bg. The first command sends as your showed up the app to own again the stdin, stdout and stderr, while there other sends the command to the background, writing anyway to stdout and stderr.
It's very clear, even to a person who is learning english. Very thanks, new subscriptor from Buenos Aires, Argentina. Cheers!
Awesome video the column command and history navigation was especially helpful thanks again.
I have two that I have found to be very useful.
- If you have a large amount of work, and you just need it to go away you can type: exit
- If you need to create a large amount of work for somebody else to get them off your back on why you are not doing anything you can SSH into a server and type: shutdown -h now
The laugh factory called... you've been fired.
And if you need a day of work: sudo rm -rf /, or alternately, sudo dd if=/dev/zero of=/dev/sda
Nice, used the ; chaining two CMDs to see how my Memory and CPU is doing in a compact view
# CMDs connected together to show how my CPU and Memory is currently doing
ps -eo comm,pcpu --sort -pcpu | head -5; ps -eo comm,pmem --sort -pmem | head -5
I just added this to a .sh script so I can run it quickly when needed.
Keep up the good work!
You may use aliases instead of scripts for this kind of stuff. Aliases are so underrated but it's by far what I use the most when I want a command to be accessed easily
Thanks. Didn't know about 'truncate'. I once had a problem with one huge log file, and I tried to simply delete it, but it didn't free space used by this file because it was used by program. I think, truncate command could help me in that case.
My favorite is using TAB to autocomplete whatever I started to type. This seems to work for any command and any argument to a command, no matter what command. I was surprised you did not mention this as if it would be common knowledge not worth mentioning. It was not for me and I've seen lots of water pass under bridges. Someone else commented about using TAB here but in such an obscure context that one might not notice it or realize what TAB will do. I would say I never fully type in any command or argument knowing full well a simple TAB press will complete what I started. This is particularly useful when dealing with directory names.
For the sake of completeness: autocomplete is great, but it is not always out of the box activated. In this case it has to be activated.
Nice vid; great tips. What is the repository I could use to install cmatrix in Oracle Linux? Thank you
If you take the blue pill, I'll show you where the repo is
26:41 instead of "truncate", i used to with "cat > your_file_name" that replace existing text with new text input, but I leave it empty by pressing "ctrl+c", then the file is empty.
you can also chain commands by using || (pipes) and it will do the opposite of &&. It will run second command only if the first one failed.
Another cool command line tool I use A LOT is "screen". Its a console windows manager that allows you have multiple consoles *running*, switch between, split screen and many more. Most cool about screen is that you can detach from it (ctrl+a D D), log out from system, log back in and attach back to it "screen -DR" and continue where you left.
I think of command && another as saying that they must both run successfully. command || another says that one or the other needs to be successful. It follows the same rules as in C and C++ regarding evaluation, where the second won't be executed unless necessary (i.e. in the && case, only if the first works, and in the second case, only if the first fails).
Very useful. Thanks for your time creating this video.
Just made my beginner life lot easier in linux!❤️🔥
instead of using "tail -f filename" I like using "less filename" and then shift+F, to force feed and update output as the file being updated.
The advantage is that if I see something I need to troubleshoot or to go up and search for a keyword that draw my attention, I can do so right away while inside the "less" command.
Even better I can do "less filename" search for the keyword, then do "shift+f" and if the keyword does show up while its feeding the content to the screen it will be immediately highlighted .
Again, some tips I din't know about after using Linux as my daily OS for 15 years! Thanks. :)
Same! Awesome tutorial! 😁
Same here.
Instead of 'cd ~' use 'cd' without arguments
Very nice. Bang colon number lets you access a numbered argument from the previous command. Bang asterisk repeats all the parameters from previous command.
Yeah !
In addition to those, !-2 refers to the second last command, and !vi to the last command starting with "vi".
@@ingokrispin3482 !vi I knew, however !-2 is new to me. Thank you!
Hi, fortunate for me i found this video at the beginning of my journey with linux ... very nice video, thank you :D
I love this channel im so grateful for it. Thanks for making me better.
Thanks for the great video. That cmatrix command and F11 is really cool! And of course all your other tips.
hi ! does popd and pushd handle multiple reference because i use a similar method that allow me to do that . Using the syntax =$(pwd)
after that you can do cd $>var_name> or other stuff like copying ... thank you so much for that "cd -" thing
Love your work Jay. You are an excellent presenter. Thank you.
Exrtremely useful! Thanks so much. Always learn a lot from your videos!
Thanks, many good tips! I agree that You can go long way doing things inefficiently by routine. It is well worth taking time to learn an adequate set of tools for the job. Problem is that the possibilities available are
sort of overwhelming, so tutorials like this are really valuable. 👍
My best youtube recommended video so far
Thank you for these valuable, time-tested tips and tricks!
Great tips. One of my favorites, not mentioned in the video is using Ctrl+x, Ctrl+e to edit complex commands and then execute them.
First one and a half minute; using Linux as a programmer for work and already learned something great; was using pushd and popd for scenarios were now I will just use cd -, awesome. Tip for you: you don't need to type cd ~, just cd without argument also works.
Yes, I saw it nowehere but somehow invente it myself. lol...
Great overview indeed! Didn't know about column utility. Btw. Ctrl-U does only delete from cursor position to the left. Ctrl-K kills from cursor to the right...
Is this EMacs key-bindings?
@@xrafter not really. These are standard bash. You may 'set -o emacs' to get emacs bindings.
Ctrl+U/K/W are actually cutted and you can paste it by Ctrl+Y
control+k also deletes a full line in nano, which is often useful after locating a line with control+dash
@@WallaceLearnEngish yes the pasting part is the most useful
I'm not sure if you mentioned this one cuz I kinda skipped that part. But just like `Ctrl + u` clears the prompt to the left of cursor, `Ctrl + k` does its reverse i.e. erases everything to the right of cursor :)
another useful shortcut is ctrl +right/left arrow . this will (mostly) tab back through the command by the word.
EX: you typed a command like "while read file;do a=$(tr [A-Z] [a-z]) ;ehco "$a" >> newfile.txt < file.txt;done"
note echo is misspelled, so you hit up arrow to bring the command back up, and hit ctrl+left arrow to go back and correct the spelling. ctrl+right moves one word to the right and ctrl+left goes left by one word. also the end key goes to the end of the line and the home key takes you to the beginning.
Great Video, I like the history time format. My tip to you, is that the "Home" key and the "End" keys do the same as "ctrl a" and "ctrl e"
The downside to using HOME/END keys is needing to lift up your hands from the keyboard. It’s a small inconvenience but CTRL+A/E is a bit more comfortable. Also, home/end placement is not consistent across keyboards. Getting used to A/E will allow muscle memory to kick in, regardless of the keyboard you’re using.
Very useful tips!
Thanks, Jay!
a brief word about stopped jobs. If you have stopped jobs and try to exit the shell, or logout, the system will tell you there are stopped jobs and put you back in an interactive prompt. If you let the job run in the background (bg or &), it will kill the job when the parent shell ends, unless you detach the process. If you lose connection with stopped jobs, then that process becomes zombied.
On systemd installations, 'journalctl -f' replaces tail -f /var/log/syslog
One of the major strengths of linux and UNIX for that matter, is the piping |
you can have some really wild commands going with putting in things like sed and awk, sort, cat, and a whole host of other commands. What is the longest pipeline (what I made up to describe the piping of commands, and not necessarily chained) you've ever created?
The longest I have created is “cat file.txt | sort | uniq | ln”
Good nerdin' on ya! I got learnt about Ctrl-L
Finally some really helpful shell video! Great channel, great content! Very useful practical tips/tricks
Nice video! Just like to mention when you Ctrl + U you cut the command to a second clipboard, you can paste with Ctrl + Y
1. I prefer less +F over tail -f
2. Could you please share your .bashrc?
In adding timestamps to the history.
Those who have edited the .bashrc file at 16:30, you guys need to run the following command after saving the file.
source ~/.bashrc
The above command will execute the .bashrc file and then after that, you can see the effect.
@linode
`. ~/.bashrc` also does the same, just saying.
For him, it's working cause he already had the variable set in his prompt. And in the next shell, it'll always get sourced. So, he might have forgot I guess
thanks
no mention of ctrl + w? I use ctrl + w a lot.. in routers/switches as well as whatever unix box I am in
Ex:
cat /etc/hosts
ctrl + w will remove 'hosts' from the line..
Ctrl+w remove "/etc/hosts" for me on Bash 5.1.16 while in zsh on Mac it removes just "hosts" as you said. Why???
Just found out... "Esc + Backspace"
Thanks for these tips that seem so basic, yet I have been using Linux for years and had never heard of some of these. Again, thanks, and God bless.
column is a great tip. ive been using linux for years and i didnt known it. thanks. btw i really like you clean and clear style. its very easy to watch
I didn't knew most of this tricks, some of them are super useful. Many thanks
Thanks a lot for sharing nice tricks.
Some of my observations I thought will share here:
Font size increase "Control Shift +" works with the plus button from row below the function key row in keyboard.
"Control +" does not work with plus button from numeric pad.
Command erase using "Control u" actually erases the characters from current position to the beginning.
Besides the `!!` substitution, there is also the `!*` substitution which substitutes everything after arg[0]. So for example if you just finished inspecting a file with `less /path/to/my/file` and decided to delete it, you can simply run `rm !*`. It's not as frequently useful, but when it is you'll be glad you know it.
I could see this being helpful when you need to chown and then chmod a file with a long pathname. This is a task I commonly do.
In the same way, you can use this to play with the last command args :
!* all args
!^ the first arg
!$ the last arg (I use this a lot..)
!:2 the second arg
!:2-$ the second to the last args
echo hello youtube video
echo !:2-3 # this is going to output
youtube video
working with linux since ages... but there were a number of useful tricks here i never knew or could not be bothered with at the time.
thanks for bringing this back to my attantion, in hindsight its a shame i never used so many of those little things before
Thanks for your shortcuts, it's really really Helpful for 🙋.
Thanks for posting. This was super helpful. And those who watch this video should also read all the comments...
Great video! Lots of great tips and tricks! Thank you.
Nice. I never knew about the the Ctrl Z / fg functionality but I've needed it plenty of times.
use tmux
Just a note here ctrl z doesn't put the process into the background it interrupts it, which pauses execution. If you want the process to run in the background you can type bg after interrupting with ctrl z. This allows the process to RUN in the background. fg will still retrieve it from the background.
Yo! Same here. And it's usually just for a quick pop out of a screen editor. Tmux is overkill for that.
One of my all time favorite Linux video.
good video mate and very fair to add the timestamps !
Some I knew, some more I didn't. Thanks for adding to my toolbox.
wow! Where have you been all my life!
Thank you!
This is fantastic Jay, subscribed
very helpful! definitely increased my productivity! thank you very much
"tail -f " to live-monitor new content in a file was a new trick for me, thanks!