Been using Linux for decades and I still learned some things from this. Thank you. Now I want to share the world changing CLI tip I learned within the last decade. tail -F The capitol F will "follow" Log files that roll over. For example if your tailing syslog and it gets rolled to syslog.1 the tail -F will continue tailing the new syslog file. I work on apps that write lots of data to their log files and roll them rapidly. The tail -F option saved me from missing things and or having to go back and grep through he log files.
OH MY GOSH. Look at that. I just learned ANOTHER cool trick from an awesome person in the community. I'm still learning things after two decades. The learning never stops, and I learn from you guys all the time!
This is currently my favourite video on this channel, for which there has been a lot of competition. A lot of the tips in here are 100% going to be applied at work after the holidays. This channel has been fantastic for ramping myself up in a lot of skills I'm using in my current role. That and I want to start up a homelab, so even more mileage to be had on this channel. Top quality content, Jay, thank you for all of this.
26:50 Also, when you chain commands with ||, you make sure that the second command runs only if the first one fails (for example: "command1 || command2" will only run command2 if command1 failed). You can then make a construction like this: (command && echo "success") || echo "failure" - this will "tell you" if the command was a success or not. If you redirect the output and perhaps include some timestamps, you have simple logging that comes in handy in scripts, for example :)
As someone relatively new to Linux, watching this video was like scratching an itch, or finally remember who the actor was in that movie you were talking about a week ago. Such a relief to have these in my toolkit now. Thanks for the video!
Ctrl + y will paste whatever you yanked with Ctrl + u, Ctrl + k, or Ctrl + w. One use for this is when you forget to type sudo in the beginning of a line. So you would Ctrl + u the line then type in sudo then Ctrl + u to bring back the commands you just yanked. Thanks for the awesome tips in the video!
22:11 Ctrl+U will not necessarily delete everything on a line. It will delete everything to the left of the cursor. (Ctrl+K will delete from the cursor to the end of the line.) To delete an entire line regardless of where the cursor is located, use Ctrl+C.
Wonderful video and the comments are gold. I remember a couple of command/shortcuts that I'm use daily. !$: Calls the last parameter of the previous command. Example: Touch anyfile.txt Nano !$ ||: Double pipe works like "OR". Only if the first command fails, run the second. Ctrl+x, ctrl +e: For long commands, open the default editor so you can write a very long command, save and it's ready in your prompt.
The reason why CTRL-z sometimes does not work with nano is that it often is disabled in the settings of nano e.g. by editing /etc/nanorc and commenting the line "set suspend". The reason for doing this is, is that people with a windows background often start pressing CTRL-z in nano thinking that would undo something, but of course it doesn't. If you are teaching linux beginners, this is a nice feature to have.
To cd to your home, just use `cd`. The tilde is only needed if you need to address a subdirectory of your home, like `cd ~/proj/scala/mini`. To exit cmatrix, just hit the q key. Many other programs use the q=quit too, like man, less, ... Beside Ctrl-a for the beginning of the line, you may use the HOME key as well, and respectively the END key for end of line.
In the last example, 'mount' is used to illustrate the 'column' command. 20 years ago, the output of 'mount' was quite easy to read. Nowadays, this is a mess because even the most basic Linux installation creates at least 20 virtual filesystems and nothing is sorted. Here are 2 good alternatives to 'mount' that are probably installed by default on all modern linux systems: The first is 'findmnt' which basically prints the same information but nicely formatted in a tree. As its name indicates, the real purpose of findmnt is to find which filesystems are matching a set of criteria but its default output matches everything. The second is 'lsblk' which prints information about the physical block devices (so no virtual filesystems). By default, the output is formatted as a tree representing the device hierarchy (LVM, LUKS, raid, ...) and the columns can also be configured (see the options -o, -f , ...)
Just type: fg and you'll get your nano session back. You could also make nano insensitive to CTRL-z by editing /etc/nanorc and commenting the line "set suspend" in that file. (sudo nano /etc/nanorc)
The applications do not see control-z. Instead they receive a suspend signal sent by the tty. You can list the terminal settings with the command stty -a You can disable the 'susp' signal by executing the following command (in your .bashrc): stty susp "" Or you can change it to something that you are less likely to hit by mistake such as stty susp "^@" However, I am not sure that changing the default terminal settings is a good idea. It is better to learn about control-z and the fg and bg commands.
@4:10 "clear" command. Yes, ctrl-l is faster and more convenient, for interactive shell execution. But for within a script, "clear" is what you probably use to clear your screen. Perhaps you can issue a ctrl-l from within a script? If someone knows how that can be done, please chime in. @23:57 "...and just delete everything on that line" (via ctrl-u) That is correct, as well as incorrect, depending on your cursor position. ctrl-u does not necessarily delete everything on the line. Rather, it deletes everything to the left of the cursor. So if you cursor happens to be at the end of the line (and it usually is at the end of the line), then, yes, it will delete the entire line. But if your cursor was not at the end of the line, then ctrl-u would not delete any characters to the right of the cursor. It would delete only the characters to the left of the cursor. @27:03 "tail -f" I prefer to use "less -iM filename" or simply "less filename", and from within less's output, press "shift F" (the "F" means "forever", as in tail the file forever). Why is "less" and from there "shift F" my preference? That "shift F" feature that is within the "less" command will do the same thing as "tail -f". But the benefit of using "less" and "shift-F" is that when you are done tailing the file, you can press ctrl-q, and return to the standard "less" pager's output -- scroll around within the output -- search through the output, etc). With "tail -f", once you ctrl-c out of it, you are returned to the shell prompt. That might be better, depending on your situation. But I find the "less" command's "shift F" to be better, somewhat more often. At any rate, you have a choice between the two. Often, when jobs run, they will duplicate their standard output (what is shown to the user) to a log file. This is often the case in a business environment, where the operators, controllers, programmers (employees) must keep a real-time eye on its progress. And there could be countless jobs running. So it is common to run "tail -f" to check on job completions and see if they succeeded or ended with errors, etc. As such... When you run "tail -f" on a log file of a job that is running, you could confuse the output from "tail -f" as the actual job, when it is really only a real-time view of the actual job (it is not the actual job, but simply the mirrored output of a log file that the job created). Whereas, with "less", followed by "shift F", you will never mistake what you are viewing. You will absolutely know that you are in your "less" pager, tail'ing a file. You will never confuse viewing the tail of a file with viewing the actual, real job that is running. If you mistakenly thought that you were doing a "tail -f", when that window happened to be the actual job, then when you run "ctrl-q" to break out of what you thought was a tail of a log, you end up performing that ctrl-q on the actual job, and you kill the job. Depending on the job, that could be a big problem. Using "shift-F" via the "less" command avoids any and all potential mix-ups and mistakes that could happen with "tail -f". ----- And, of course, another great video with clear and useful tips. Cheers!
I have been working with Linux/Unix systems for over 20 years. I have worked with Solaris, SCO, FreeBSD as well as most major linux distros. I stumbled upon this video and thought it would be some basic commands I already knew. But, I was surprised that some of the commands were new and I will start using them right away. The "sudo !!" as well as adding a space to a command would not appear in the history. Stuff like that was very useful. I have a bash script that will go and search for passwords in history and clear them out, but this is much better. Thank You. Finally I would add the "watch" and "timeout" command. The watch command runs whatever command every 2 seconds. This is useful for getting realtime file sizes. The timeout command is great when you want to run a command for X amount of time, for example tcpdump.
Linode is the best sponsor on RUclips :) I need to spend more time in Linux console/ terminal. Thank you for this video. I need to watch it again with pen and paper.
Well so much things you can learn from Jay......and Silent BOB. Jokes aside. This is one of the best learning places on the net for Linux. Really. Thank you so much for the time you got in this Jay.
Incredible. I have been pecking away at command line mostly hating the experience and didn’t know more than 90% of these commands. Not a full time Linux user but have been using Linux over the years. I think I’m going to have to incorporate as much of these commands and possible going forward. Thank you for sharing this knowledge, Jay!
Me too. The problem is then I log into another machine, and my aliases aren't there. I love aliasing "lt" (ls -lht | head) but whenever I'm on a new box, I get (of course) Command 'lt' not found, but can be installed with: sudo apt install looptools
aliasing, and also functions. instead_of_an_alias() { do_something; } my_func() { local A="$1" shift for s; do echo "$s:$A" done } and so on. I mostly use functions.
I've been a Fedora man since the days of Redhat 2 & 3, when you had several CD's for the install. Primarily as a revolt against the Bill Gateans. Though my hangup was with the GUI and never really got proficient on the command-line, and only using it when I absolutely had too. And then often with difficulty. However now that I am building my own home network (5 units, so far...) including a Xeon server with 3 drives and raid, I am taking a more sincere approach to, and interest in, the command-line. Thus my presence here to catch your videos. So, thank you very much. I will be watching a lot more as time goes on, and yes... I DID subscribe.
Thanks for the video. Most of the tricks were already known, but I found some new ones. You asked for what you missed, well here you go: xargs command, splitting long commands in multiple lines with backslash, grepping stuff, watch command, searching for recently modified files with find command
I have learned so much since discovering your channel! This video all in his own is like an excellent little cheat sheet that you might have with you for a final exam. If there is not a text / transcript version of this already available I may have to get on that myself even if it is just for myself, a lot of these were very useful, thank you 😮👍🏽
CTRL-A and CTRL-E are also implemented with HOME and END respectively with most terminal software. Much easier to remember HOME for the start/home of the line and END for the end!
@@xpusostomos pfft, vi is a user unfriendly editor that only die hard long term Linux users hold on to. They seem to think you are not a true Linux user if you don't use it which is just plain stupid, it's a "no true Scotsman" fallacy that needs to end and besides, why make things harder for yourself when there are easier tools to use? Just use tools you like to use, if the job gets done either way then what does it matter? 😏 Just a small rant about vi, nothing wrong with what you said 🙂
thank you for these great tips. I also want to mention the "| more" command to view at long outputs in the CLI running over multiple terminal heights. You type your listing command or cat or whatever and add "| more" at the end f the command. The output starts with its first screen and stops for you to read. Then you resume the output with the space key. At the end of the list you leave that mode with a "q" command for 'quit'.
Less is generally more useful than more. I'm not sure I know of a case where more is preferable to less, except on some kind of minimal embedded system where less is omitted to save space. Less lets you scroll back up. More only goes down.
cd ~ is same as just cd. Ctrl-w will delete word instead of whole thing like Ctrl-u Ctrl-k is like Ctrl-u but for things after the cursor and not before.
Not sure whether it was mentioned, but e.g. ~john reverse to the home folder of the user named john, not necessarily the logged in user. So cd ~harry/Videos changes to something like /home/harry/Videos.
sounds good, BUT just tried it in mint-xfce and it did not like it. It replied with "bash: bg: current: no such job". Perhaps this is distro dependent?
@@jim7smith It's definitely not distro dependent, so I'm not sure what went wrong for you. After you hit ^Z, you should be able to type "jobs" to see what you've got running. Also, putting interactive processes like editors into the background is a bad idea.
@@jim7smith Ctrl-Z sends the SUSPEND signal to the process. Processes can trap this signal and control what happens next, possibly ignoring, possibly terminating. If you get bg: no current job, that probably means the program terminated in response to SIGSUSPEND. Which command did you try Ctrl-Z with, out of curiosity?
I just want to say thanks Jay for al your content, I've been using Linux for quite a few years alongside MacOS, ( I use Arch btw ) and I learn and discover something new every week with your videos. It was your Arch install video that got me started with that, and I've not looked back.
I bet a lot of people don't fully realize that this was the only way to interact with a system even before the luxury of a mouse and desktop environment, and that is amazing that it still is sometimes the best way.
Not only will ";" run all the commands and "&&" will run them all if no mistakes are encountered, the "||" will ONLY fun the following commands IF an error happens.
Thank you so much! This has been very informative. Of all the 15 tips, only 1 I knew, despite having used Linux for up to 5 years. Keeps the great content coming, man :D
@@f4zkh4n Neither can I. Have tried it, works when your needs do not clashes, but doesn't when there are things you simply cannot do in Linux. So these days, I just use WSL. Works best as a compromise.
@@andmefikri7555 i'm going to try jump ship once again. win10 telemetry has always been outrageous and left a bad taste in my mouth. win11 seems even in worse in more ways than one, complete no go. WSL has been cool though and android apps running in win11 is also the one enticing thing about it.
Thanks for you patience and to explain the beautiful tricks, i knew most of them are experts in this but being newer, even drop of learning is useful. The last command can be seen clear after pressing F11.
I've been running Linux since 1998, and I love the command line ... but I never knew about the "column" command. After I learned how to use Vim, and found that I really like it, I learned that Bash has a vi-mode ("set -o vi"), so I tried enabling it, almost as a joke, just to see how long it would take to annoy me. To my surprise, I still use it to this day, and I find its editing and searching commands far easier to remember than the emacs-mode. I always had trouble remembering how to use the search feature (ctrl-r or ctrl-i or whatever it is), but in vi-mode it's totally intuitive, at least for me (/ to search, j and k to scroll through matches).
Run _info coreutils_ and you'll find a whole host of other useful commands like _column_ . Edit: actually _column_ is not a coreutil, but part of the _util-linux_ package, another bundle of commands that should be installed by default.
Pretty much everyone knows how to glob things with *, but I've found fewer people know about brace expansion {}. If you want to repeat a command for a list of strings, you can list them inline. Eg. ls {dir1,dir2}/subdir_named_same It can be very useful whenever there are repeated patterns in directory structures.
I often use even nested curly braces (or is it curly brackets?) to avoid typing sprees and let the shell do the hard work of expanding all alternations. I wonder if you knew that you can even avoid the seq comnand (if your Bash isn't too dated) and use the magic power of curly brackets' counting ability? Here is what I often do to create a bunch of temporaral mount points whenever I tinker with several filesystems in parallel. # mkdir /mnt/tmp{1..9}
And of course here you could do ls dir{1,2}/subdir_named_same. Also there are square brackets that do something slightly different. Braces always expand, no matter whether the result names a file or not. But $ ls dir[0-9]/hello will expand to anything of the form dir4/hello provided that it exists. Also ? is worth knowing about (it matches precisely one character, whereas * matches any string, including the 0-length string "" so hello?*world matches any file starting with hello and ending with world and which has at least something between hello and world.
What an awesome video. I've been using linux ... just enough to get by here and there and thought I knew some commands and I knew only one of these (history). Thanks for sharing.
as a Unix preson for ~30 you always forget the basics and go back to programs like "ex" so you do not need to use "vi" for basic search and replace or vim ( something I still do not use), that was a good reminder and that column command was useful, I have never used that after years of looking at unformatted text and using the echo and cut -d to get my columns
Nice tips for a newbie 👌🏻 Actually what I've learned from this video is the name of the & symbol in English!! Ampersand!! So... Thanks!! Cool name 😎 Ampersand, ampersand!! Love it
If you use ctrl-R to recall commands, you should know that ctrl-S moves you forward in the search list (in case you pass the one you're looking for). Also, related to all the cd variants, see 'man bash' and look for CDPATH. If you have a set of path values set, say 'CDPATH=.:~', then cd tries to cd to '/' for each entry in the path. 'cd bin' attempts first 'cd ./bin', if that fails, then 'cd ~/bin' and so on.
Ctrl-S doesn't work for me, neither on Windows in Putty or native terminal in GNOME, it just stucks untill you press Ctrl+C couple times. UPD: you need to set "stty -ixon" manually or in ".bash_profile" to disable XON/XOFF feature that takes over Ctrl+S.
@@PendalfCell You got it, 'stty -ixon' is the solution. And if you forget and get stuck, ctrl-Q is the "xon" key that turns the tty back on, so you can continue without breaking out in the middle...
Also there is a trick if you forgot to run long running command with nohup, or run this command in screen, and you need to close the session, just run disown -a && exit
Something I never realised until recently, when I thought about implementing this myself, was that cp and mv have a -t option to specify the target folder. If you want to copy folder1 into folder0, you would often do $ cp -r folder1 folder 0 now there is a source of potential accidents if doing this yourself: you start typing a long cp command $ cp -r folder1 folder2 folder3 folder4 and before tying the final folder0, you accidentally hit enter and folder1..3 get copied into folder4. By specifying the target folder first, via $ cp -t folder0 folder1 folder2 folder3 this kind of keyboard slip can't cause problems in the same way. This also ensures that the target is definitely a directory, so avoiding the accident where you mistakenly copy one file over another. I wish I knew about this a long time ago, and in writing bash scripts I've often written crude snippets to approximate this behaviour. This works with both cp and mv.
Jumping to be the beginning and end of the line is very useful. Is there a command to go in the middle of the line or move word by word back and forth? Or maybe 3 words back and forth at once?
Well well well... As an outdated Unix user myself, coming back to the nix community, migrating myself from Windows, I am inclined to rekindle myself to CLI before I even can go forward with the nix system. You got my subs from this video. Gonna get myself updated with your Linux knowledge on this channel. Just to add a little note though. This symbol ">" is also useful in terminal or CLI or CMD.
One tip I think is similar to "!!" to repeat the entire previous command, is to use "!$" to repeat just the last argument from the previous command. If I "cat ~/longpath/somefile", then decide I want to edit the same file, it's a simple "vim !$". It's also useful when you "ls ~/longpath/somelongdir", see the file you want to edit, and can then just "vim !$/somefile".
hi. I have learned some new tricks with your video. thanks. sometimes the kernel writes some junk into swap and keeps it there. I like to clear the swap with: sudo swapoff -a; sleep 2; sudo swapon -a I usually find it with Ctrl+R poff, but one can create an alias for the command, I think
19:45 to 19:55. If you, like me, changed your copy and paste from ctrl shift c and v to simply ctrl c and ctrl v..You MAY find that ctrl c obviously won't stop an active running....thing within terminal If that is the case..use ctrl z
ctrl-z doesn't kill the process, it stops it. You are then left to manually kill it with "kill %1" If you changed copy in the terminal to ctrl-c, then you are left with no easy way to kill a process, which is really disasterous in the terminal. If you really want to do that, you should change your kill character to something else. e.g. by entering "stty intr ^G" will change it to ^G instead of ^C.
@@xpusostomos Interesting to know. Thanks for the info. I'm guessing you never shut down/turn off your PC? If that is the case..your concerns are far more applicable to you than they are to me. When you shut down/turn off any Linux distro booted up pc, it kills any/all processes one way or another. *shrugs* either way. again.. Thanks for the info :D Cheers.
@@motoryzen erm.. you shutting down your PC every time you copy text? 🤔 Or are you just accumulating hundreds of stopped processes until you run out of memory and it dies ?
deleting single words to the right of the cursor with ctrl+del or to the right with alt+backspace is also useful, same as navigating around whole words with ctrl+arrow
In most terminals: CTRL-SHIFT-C to copy, CTRL-SHIFT-V to past. It is annoying, but makes sense. CTRL-C is "COPY" in desktop applications. But it is the kill-process in the terminal.
Hi great video; if you add alias cmatrix='cmatrix -s' to .bash_aliases cmatrix will act like a screen saver i.e. any key subsequently pressed will exit cmatrix.
opposed to ctrl+a and ctrl+e to go to the start and end of a line i use the buttons home and end buttons abothe the arrows, its muscle memory and works (if not should) everywhere i can type text
Those keyboard shortcuts (cntrl-a, cntrl-e, cntrl-u, etc.) are Emacs shortcuts. Others work too - from next-word (ESC-f) to delete-to-EOL (cntrl-k), etc. If you use Emacs a lot, it's handy!
The cd - is incredibly useful when combined with fasd. For instance i can jump to a directory by doing z project, and then jump back again using cd - While cd .. is usefull for jumping back across time and space cd - is golden.
@ - "Searching through command history" is actually an emacs keybinding for reverse search. You can use others too: c-a (go to beginning of a line) c-e (go to end) c-d (delete a char) etc.
For the vi folks like me. In your bash terminal type _set -o vi_ and you have vi key bindings (e.g. _Esc / wget_ would search backwards in bash's history for your last wget command, hitting n would take you to the next and so forth) Typing _set +vi_ toggles back to the default emacs key bindings.
great tools you show here and great that the community is adding their more than 2 cents. I like aliases, because I can nest an alias within an alias without ever calling it, and its also a pit fall of naming aliases...config push origin HEAD:master cps -f origin master these 2 commands let me reset my git bare repo to a new system, where config is '/usr/bin/git --git-dir=$HOME/bare/ --work-tree=$HOME', and then cps is config push, and this right here is where I used config as a previous alias in a new alias.
Very useful video for new to linux people like me. I have a doubt, what happens if we combine 3 commands with && sign? I tried alias upd="sudo apt update && sudo apt upgrade && sudo apt dist-upgrade" but seems 3rd command isnt working. When i run it without alias with the same syntax, those 3 works. So I dunno wats wrong.. If u can help pls.. Thanks in advance.
Thank you for these Tips. I am using Ubuntu, and I could not use Ctrl + Shift + +, to increase the font size, it doesn't take, is there another way to do it?
How do i find the boot time for my Linux Mint Uma using the terminal as I have a very slow boot time - in the vicinity of four minutes and can I change the boot time via the terminal command?
Only piece of advice I can offer for the truncating files, if you want to erase a full file, you can run "> /var/log/syslog" as an example, it's a blank redirect that wipes the file clean, easier than truncate. You could add more with grep, less, tmux, wc, sed/awk, vim to the video and then it might be close to being the complete guide.
i like "cut" command. For example to extract one column of CSV file you can use it and redirect output to "result file". with grep you can "cut and filter" csv easy
When I make a typo in a command I like re-running it by typing ^typo^correction^. For example "mdir someDir" (oops). Now enter "^d^kd^" to get the intended "mkdir someDir".
Been using Linux for decades and I still learned some things from this. Thank you. Now I want to share the world changing CLI tip I learned within the last decade.
tail -F
The capitol F will "follow" Log files that roll over. For example if your tailing syslog and it gets rolled to syslog.1 the tail -F will continue tailing the new syslog file.
I work on apps that write lots of data to their log files and roll them rapidly. The tail -F option saved me from missing things and or having to go back and grep through he log files.
OH MY GOSH. Look at that. I just learned ANOTHER cool trick from an awesome person in the community. I'm still learning things after two decades. The learning never stops, and I learn from you guys all the time!
This is currently my favourite video on this channel, for which there has been a lot of competition. A lot of the tips in here are 100% going to be applied at work after the holidays. This channel has been fantastic for ramping myself up in a lot of skills I'm using in my current role. That and I want to start up a homelab, so even more mileage to be had on this channel. Top quality content, Jay, thank you for all of this.
26:50
Also, when you chain commands with ||, you make sure that the second command runs only if the first one fails (for example: "command1 || command2" will only run command2 if command1 failed). You can then make a construction like this:
(command && echo "success") || echo "failure" - this will "tell you" if the command was a success or not. If you redirect the output and perhaps include some timestamps, you have simple logging that comes in handy in scripts, for example :)
That's cool!
have you tried:
echo $?
?
As someone relatively new to Linux, watching this video was like scratching an itch, or finally remember who the actor was in that movie you were talking about a week ago. Such a relief to have these in my toolkit now. Thanks for the video!
Ctrl + y will paste whatever you yanked with Ctrl + u, Ctrl + k, or Ctrl + w.
One use for this is when you forget to type sudo in the beginning of a line. So you would Ctrl + u the line then type in sudo then Ctrl + u to bring back the commands you just yanked.
Thanks for the awesome tips in the video!
22:11 Ctrl+U will not necessarily delete everything on a line. It will delete everything to the left of the cursor. (Ctrl+K will delete from the cursor to the end of the line.)
To delete an entire line regardless of where the cursor is located, use Ctrl+C.
Wonderful video and the comments are gold.
I remember a couple of command/shortcuts that I'm use daily.
!$: Calls the last parameter of the previous command.
Example:
Touch anyfile.txt
Nano !$
||: Double pipe works like "OR".
Only if the first command fails, run the second.
Ctrl+x, ctrl +e: For long commands, open the default editor so you can write a very long command, save and it's ready in your prompt.
15:30 - %Y-%m-%d is the same as %F in bash. Thus HISTTIMEFORMAT='%F %T ' gives the same results in fewer keystrokes.
Nice! Thanks for the tip.
Cool!
The reason why CTRL-z sometimes does not work with nano is that it often is disabled in the settings of nano e.g. by editing /etc/nanorc and commenting the line "set suspend". The reason for doing this is, is that people with a windows background often start pressing CTRL-z in nano thinking that would undo something, but of course it doesn't. If you are teaching linux beginners, this is a nice feature to have.
I remember having pain in a$$ with this feature when I switched from Windows to Linux ))
To cd to your home, just use `cd`. The tilde is only needed if you need to address a subdirectory of your home, like `cd ~/proj/scala/mini`.
To exit cmatrix, just hit the q key. Many other programs use the q=quit too, like man, less, ...
Beside Ctrl-a for the beginning of the line, you may use the HOME key as well, and respectively the END key for end of line.
Also to cd to another user's home directory:
cd ~bob
In the last example, 'mount' is used to illustrate the 'column' command. 20 years ago, the output of 'mount' was quite easy to read. Nowadays, this is a mess because even the most basic Linux installation creates at least 20 virtual filesystems and nothing is sorted.
Here are 2 good alternatives to 'mount' that are probably installed by default on all modern linux systems:
The first is 'findmnt' which basically prints the same information but nicely formatted in a tree. As its name indicates, the real purpose of findmnt is to find which filesystems are matching a set of criteria but its default output matches everything.
The second is 'lsblk' which prints information about the physical block devices (so no virtual filesystems). By default, the output is formatted as a tree representing the device hierarchy (LVM, LUKS, raid, ...) and the columns can also be configured (see the options -o, -f , ...)
I learn something new every day. in this case findmnt.
Thanks!
As a linux noob, can't tell you how many times I've accidently hit control-z and then had no idea how to get back to that screen. Thanks Jay!
Just type: fg and you'll get your nano session back. You could also make nano insensitive to CTRL-z by editing /etc/nanorc and commenting the line "set suspend" in that file. (sudo nano /etc/nanorc)
were you trying to hit ctrl A instead to select all?
The applications do not see control-z. Instead they receive a suspend signal sent by the tty. You can list the terminal settings with the command stty -a
You can disable the 'susp' signal by executing the following command (in your .bashrc):
stty susp ""
Or you can change it to something that you are less likely to hit by mistake such as
stty susp "^@"
However, I am not sure that changing the default terminal settings is a good idea. It is better to learn about control-z and the fg and bg commands.
@4:10 "clear" command.
Yes, ctrl-l is faster and more convenient, for interactive shell execution.
But for within a script, "clear" is what you probably use to clear your screen.
Perhaps you can issue a ctrl-l from within a script?
If someone knows how that can be done, please chime in.
@23:57 "...and just delete everything on that line" (via ctrl-u)
That is correct, as well as incorrect, depending on your cursor position.
ctrl-u does not necessarily delete everything on the line. Rather, it deletes everything to the left of the cursor. So if you cursor happens to be at the end of the line (and it usually is at the end of the line), then, yes, it will delete the entire line.
But if your cursor was not at the end of the line, then ctrl-u would not delete any characters to the right of the cursor. It would delete only the characters to the left of the cursor.
@27:03 "tail -f"
I prefer to use "less -iM filename" or simply "less filename", and from within less's output, press "shift F" (the "F" means "forever", as in tail the file forever).
Why is "less" and from there "shift F" my preference?
That "shift F" feature that is within the "less" command will do the same thing as "tail -f". But the benefit of using "less" and "shift-F" is that when you are done tailing the file, you can press ctrl-q, and return to the standard "less" pager's output -- scroll around within the output -- search through the output, etc).
With "tail -f", once you ctrl-c out of it, you are returned to the shell prompt. That might be better, depending on your situation. But I find the "less" command's "shift F" to be better, somewhat more often. At any rate, you have a choice between the two.
Often, when jobs run, they will duplicate their standard output (what is shown to the user) to a log file. This is often the case in a business environment, where the operators, controllers, programmers (employees) must keep a real-time eye on its progress. And there could be countless jobs running. So it is common to run "tail -f" to check on job completions and see if they succeeded or ended with errors, etc.
As such...
When you run "tail -f" on a log file of a job that is running, you could confuse the output from "tail -f" as the actual job, when it is really only a real-time view of the actual job (it is not the actual job, but simply the mirrored output of a log file that the job created).
Whereas, with "less", followed by "shift F", you will never mistake what you are viewing. You will absolutely know that you are in your "less" pager, tail'ing a file. You will never confuse viewing the tail of a file with viewing the actual, real job that is running.
If you mistakenly thought that you were doing a "tail -f", when that window happened to be the actual job, then when you run "ctrl-q" to break out of what you thought was a tail of a log, you end up performing that ctrl-q on the actual job, and you kill the job. Depending on the job, that could be a big problem.
Using "shift-F" via the "less" command avoids any and all potential mix-ups and mistakes that could happen with "tail -f".
-----
And, of course, another great video with clear and useful tips.
Cheers!
I have been working with Linux/Unix systems for over 20 years. I have worked with Solaris, SCO, FreeBSD as well as most major linux distros. I stumbled upon this video and thought it would be some basic commands I already knew. But, I was surprised that some of the commands were new and I will start using them right away. The "sudo !!" as well as adding a space to a command would not appear in the history. Stuff like that was very useful. I have a bash script that will go and search for passwords in history and clear them out, but this is much better. Thank You. Finally I would add the "watch" and "timeout" command. The watch command runs whatever command every 2 seconds. This is useful for getting realtime file sizes. The timeout command is great when you want to run a command for X amount of time, for example tcpdump.
Linode is the best sponsor on RUclips :)
I need to spend more time in Linux console/ terminal.
Thank you for this video. I need to watch it again with pen and paper.
just write "cd" will take you to home
That's a cool trick thanks mate!
Well so much things you can learn from Jay......and Silent BOB. Jokes aside. This is one of the best learning places on the net for Linux. Really. Thank you so much for the time you got in this Jay.
Hi Jay, This will take me some time to wrap my head around all of this. Little by little I will work on this. Thank you so much for this video.
Love the pushd and popd - obviously from Assembly language. "BASIC'ers peek and poke, Assemblers push and pop!" :)
Thanks for all your help Jay. You are a true blessing for those of us who are new to Linux. Keep up the good work my friend it is truly appreciated.
Incredible. I have been pecking away at command line mostly hating the experience and didn’t know more than 90% of these commands. Not a full time Linux user but have been using Linux over the years. I think I’m going to have to incorporate as much of these commands and possible going forward. Thank you for sharing this knowledge, Jay!
These tips are for the bash shell, the default for Linux distros
Jay, I'm kinda surprised that you didn't include Alias commands. Being a Sys admin, I use Alias commands all of the time.
Me too. The problem is then I log into another machine, and my aliases aren't there. I love aliasing "lt" (ls -lht | head) but whenever I'm on a new box, I get (of course)
Command 'lt' not found, but can be installed with:
sudo apt install looptools
aliasing, and also functions.
instead_of_an_alias() { do_something; }
my_func() {
local A="$1"
shift
for s; do
echo "$s:$A"
done
}
and so on. I mostly use functions.
I've been a Fedora man since the days of Redhat 2 & 3, when you had several CD's for the install. Primarily as a revolt against the Bill Gateans. Though my hangup was with the GUI and never really got proficient on the command-line, and only using it when I absolutely had too. And then often with difficulty.
However now that I am building my own home network (5 units, so far...) including a Xeon server with 3 drives and raid, I am taking a more sincere approach to, and interest in, the command-line. Thus my presence here to catch your videos. So, thank you very much. I will be watching a lot more as time goes on, and yes... I DID subscribe.
Thanks for the video. Most of the tricks were already known, but I found some new ones.
You asked for what you missed, well here you go: xargs command, splitting long commands in multiple lines with backslash, grepping stuff, watch command, searching for recently modified files with find command
I have learned so much since discovering your channel! This video all in his own is like an excellent little cheat sheet that you might have with you for a final exam. If there is not a text / transcript version of this already available I may have to get on that myself even if it is just for myself, a lot of these were very useful, thank you 😮👍🏽
I've been working with linux for more than 15 years now, but I still learned a lot from this, thx
The Ctrl + Left or Right arrow, allowing you to go to the previous/next word within a command, is pretty useful too.
CTRL-A and CTRL-E are also implemented with HOME and END respectively with most terminal software. Much easier to remember HOME for the start/home of the line and END for the end!
If you're an emacs or mg editor user, you should learn it anyway. If you're a "vi" user, put the shell into "vi" mode.
@@xpusostomos pfft, vi is a user unfriendly editor that only die hard long term Linux users hold on to. They seem to think you are not a true Linux user if you don't use it which is just plain stupid, it's a "no true Scotsman" fallacy that needs to end and besides, why make things harder for yourself when there are easier tools to use? Just use tools you like to use, if the job gets done either way then what does it matter? 😏
Just a small rant about vi, nothing wrong with what you said 🙂
Best Linux tutorials I ever had. I wish i found it 8 years ago :D So much time was used unprodactive
thank you for these great tips. I also want to mention the "| more" command to view at long outputs in the CLI running over multiple terminal heights.
You type your listing command or cat or whatever and add "| more" at the end f the command. The output starts with its first screen and stops for you to read. Then you resume the output with the space key. At the end of the list you leave that mode with a "q" command for 'quit'.
Less is generally more useful than more. I'm not sure I know of a case where more is preferable to less, except on some kind of minimal embedded system where less is omitted to save space. Less lets you scroll back up. More only goes down.
cd ~ is same as just cd.
Ctrl-w will delete word instead of whole thing like Ctrl-u
Ctrl-k is like Ctrl-u but for things after the cursor and not before.
Not sure whether it was mentioned, but e.g. ~john reverse to the home folder of the user named john, not necessarily the logged in user. So cd ~harry/Videos changes to something like /home/harry/Videos.
I just want to thank you for your well crafted Linux tutorials. Oh, and am loving cmatrix!
control-z doesn't send your process to the background; it *stops* it. To send it running to the background, use 'bg'
sounds good, BUT just tried it in mint-xfce and it did not like it. It replied with "bash: bg: current: no such job". Perhaps this is distro dependent?
@@jim7smith It's definitely not distro dependent, so I'm not sure what went wrong for you. After you hit ^Z, you should be able to type "jobs" to see what you've got running. Also, putting interactive processes like editors into the background is a bad idea.
@bofhorg... a matter of terminology... Control-z makes it stopped in the background. "bg" makes it running in the background.
@@jim7smith Ctrl-Z sends the SUSPEND signal to the process. Processes can trap this signal and control what happens next, possibly ignoring, possibly terminating. If you get bg: no current job, that probably means the program terminated in response to SIGSUSPEND. Which command did you try Ctrl-Z with, out of curiosity?
Ctrl +z and immediately type bg
Then your process will run on background
I just want to say thanks Jay for al your content, I've been using Linux for quite a few years alongside MacOS, ( I use Arch btw ) and I learn and discover something new every week with your videos. It was your Arch install video that got me started with that, and I've not looked back.
I bet a lot of people don't fully realize that this was the only way to interact with a system even before the luxury of a mouse and desktop environment, and that is amazing that it still is sometimes the best way.
Some of these concepts even predate monitors, your output would have been text actually printed on a roll of paper.
That spare hand can be very, well, handy😶
Not only will ";" run all the commands and "&&" will run them all if no mistakes are encountered, the "||" will ONLY fun the following commands IF an error happens.
Thank you so much! This has been very informative. Of all the 15 tips, only 1 I knew, despite having used Linux for up to 5 years. Keeps the great content coming, man :D
meanwhile I knew all but 1 and still can't seem to make the switch from windows despite many attempts.
@@f4zkh4n Neither can I. Have tried it, works when your needs do not clashes, but doesn't when there are things you simply cannot do in Linux. So these days, I just use WSL. Works best as a compromise.
@@andmefikri7555 i'm going to try jump ship once again. win10 telemetry has always been outrageous and left a bad taste in my mouth. win11 seems even in worse in more ways than one, complete no go. WSL has been cool though and android apps running in win11 is also the one enticing thing about it.
Thanks for you patience and to explain the beautiful tricks, i knew most of them are experts in this but being newer, even drop of learning is useful.
The last command can be seen clear after pressing F11.
I've been running Linux since 1998, and I love the command line ... but I never knew about the "column" command.
After I learned how to use Vim, and found that I really like it, I learned that Bash has a vi-mode ("set -o vi"), so I tried enabling it, almost as a joke, just to see how long it would take to annoy me. To my surprise, I still use it to this day, and I find its editing and searching commands far easier to remember than the emacs-mode. I always had trouble remembering how to use the search feature (ctrl-r or ctrl-i or whatever it is), but in vi-mode it's totally intuitive, at least for me (/ to search, j and k to scroll through matches).
Cool
Run _info coreutils_ and you'll find a whole host of other useful commands like _column_ .
Edit: actually _column_ is not a coreutil, but part of the _util-linux_ package, another bundle of commands that should be installed by default.
Yes, intuitive for vi users. Of course, you should change to using emacs :-P
"After I learned how to use Vim, and found that I really like it,..."
Me, a vim rookie: "LIAR!"
@@bfahren
Confidence is the food of the wise man, and the liquor of the fool. Vim is fast for simple edits and limited for difficult work
Thanks so much!!! I'm brand new to Linux and fairly new to your channel, so the beginner material is perfect for me!
Pretty much everyone knows how to glob things with *, but I've found fewer people know about brace expansion {}.
If you want to repeat a command for a list of strings, you can list them inline.
Eg.
ls {dir1,dir2}/subdir_named_same
It can be very useful whenever there are repeated patterns in directory structures.
I often use even nested curly braces (or is it curly brackets?)
to avoid typing sprees and let the shell do the hard work of expanding all alternations.
I wonder if you knew that you can even avoid the seq comnand (if your Bash isn't too dated) and use the magic power of curly brackets' counting ability?
Here is what I often do to create a bunch of temporaral mount points whenever I tinker with several filesystems in parallel.
# mkdir /mnt/tmp{1..9}
Or when you have to create multiple directories in the same location, saves some time.
Mkdir {dir1, dir2, dir3}
And of course here you could do ls dir{1,2}/subdir_named_same. Also there are square brackets that do something slightly different. Braces always expand, no matter whether the result names a file or not. But
$ ls dir[0-9]/hello
will expand to anything of the form dir4/hello provided that it exists. Also ? is worth knowing about (it matches precisely one character, whereas * matches any string, including the 0-length string "" so hello?*world matches any file starting with hello and ending with world and which has at least something between hello and world.
What an awesome video. I've been using linux ... just enough to get by here and there and thought I knew some commands and I knew only one of these (history). Thanks for sharing.
I've been using Linux for a long time, but some of the commands here were unknown to me. Thank you,
Oh God, this video is the best Christmas present I've ever had. Thank you very much!
There are loads of cli key-commands and escape sequences for both emacs mode and vi mode, they can be listed with:
bind -p
You just ruined Jay's entire series he planned on "Terminal Tricks" with this "bind -p" command. Good job! ;-)
This was just great. Fitted straight in, right now, in my atempt to learn linux. Thanks!
as a Unix preson for ~30 you always forget the basics and go back to programs like "ex" so you do not need to use "vi" for basic search and replace or vim ( something I still do not use), that was a good reminder and that column command was useful, I have never used that after years of looking at unformatted text and using the echo and cut -d to get my columns
Nice tips for a newbie 👌🏻
Actually what I've learned from this video is the name of the & symbol in English!! Ampersand!! So... Thanks!!
Cool name 😎
Ampersand, ampersand!! Love it
If you use ctrl-R to recall commands, you should know that ctrl-S moves you forward in the search list (in case you pass the one you're looking for).
Also, related to all the cd variants, see 'man bash' and look for CDPATH. If you have a set of path values set, say 'CDPATH=.:~', then cd tries to cd to '/' for each entry in the path. 'cd bin' attempts first 'cd ./bin', if that fails, then 'cd ~/bin' and so on.
Ctrl-S doesn't work for me, neither on Windows in Putty or native terminal in GNOME, it just stucks untill you press Ctrl+C couple times.
UPD: you need to set "stty -ixon" manually or in ".bash_profile" to disable XON/XOFF feature that takes over Ctrl+S.
@@PendalfCell You got it, 'stty -ixon' is the solution. And if you forget and get stuck, ctrl-Q is the "xon" key that turns the tty back on, so you can continue without breaking out in the middle...
@@d00dEEE I was just about to shout c-Q hehe +1
There is always something new to learn with Linux . Good content, thank you.
Also there is a trick if you forgot to run long running command with nohup, or run this command in screen, and you need to close the session, just run disown -a && exit
4:10 to 4:20. very cool. Much respect for ctrl + l ( lower case L btw) I've been typing clear and enter this whole time.
but clear actually clears instead of just 'pushing down' :D
You can also C-L after you typed your command, just before pressing enter for example :o)
who else watches MauLer's long format videos in more or less one sitting on a weekend day? very enjoyable
Thanks very much for making this video! I found the information to be VERY USEFUL, very helpful; I appreciate your time and effort!
Something I never realised until recently, when I thought about implementing this myself, was that cp and mv have a -t option to specify the target folder. If you want to copy folder1 into folder0, you would often do
$ cp -r folder1 folder 0
now there is a source of potential accidents if doing this yourself: you start typing a long cp command
$ cp -r folder1 folder2 folder3 folder4
and before tying the final folder0, you accidentally hit enter and folder1..3 get copied into folder4.
By specifying the target folder first, via
$ cp -t folder0 folder1 folder2 folder3
this kind of keyboard slip can't cause problems in the same way. This also ensures that the target is definitely a directory, so avoiding the accident where you mistakenly copy one file over another. I wish I knew about this a long time ago, and in writing bash scripts I've often written crude snippets to approximate this behaviour.
This works with both cp and mv.
Jumping to be the beginning and end of the line is very useful. Is there a command to go in the middle of the line or move word by word back and forth? Or maybe 3 words back and forth at once?
love how all of the other related tricks come out after seeing this.
Well well well... As an outdated Unix user myself, coming back to the nix community, migrating myself from Windows, I am inclined to rekindle myself to CLI before I even can go forward with the nix system. You got my subs from this video. Gonna get myself updated with your Linux knowledge on this channel. Just to add a little note though. This symbol ">" is also useful in terminal or CLI or CMD.
Not to mention ">>", "
One tip I think is similar to "!!" to repeat the entire previous command, is to use "!$" to repeat just the last argument from the previous command. If I "cat ~/longpath/somefile", then decide I want to edit the same file, it's a simple "vim !$". It's also useful when you "ls ~/longpath/somelongdir", see the file you want to edit, and can then just "vim !$/somefile".
hi. I have learned some new tricks with your video. thanks.
sometimes the kernel writes some junk into swap and keeps it there. I like to clear the swap with:
sudo swapoff -a; sleep 2; sudo swapon -a
I usually find it with Ctrl+R poff, but one can create an alias for the command, I think
Part 2 please..... ;-) Great Video!
22:19 I usually use "home", "end", "ctrl + arrow keys" to jump over command line text
In some "dumbs" terminal home, end or ctrl+arrows doesn't work, so is good to keep this in mind.
19:45 to 19:55. If you, like me, changed your copy and paste from ctrl shift c and v to simply ctrl c and ctrl v..You MAY find that ctrl c obviously won't stop an active running....thing within terminal
If that is the case..use ctrl z
ctrl-z doesn't kill the process, it stops it. You are then left to manually kill it with "kill %1" If you changed copy in the terminal to ctrl-c, then you are left with no easy way to kill a process, which is really disasterous in the terminal. If you really want to do that, you should change your kill character to something else. e.g. by entering "stty intr ^G" will change it to ^G instead of ^C.
@@xpusostomos Interesting to know. Thanks for the info.
I'm guessing you never shut down/turn off your PC? If that is the case..your concerns are far more applicable to you than they are to me. When you shut down/turn off any Linux distro booted up pc, it kills any/all processes one way or another. *shrugs*
either way. again.. Thanks for the info :D Cheers.
@@motoryzen erm.. you shutting down your PC every time you copy text? 🤔 Or are you just accumulating hundreds of stopped processes until you run out of memory and it dies ?
Great tutorial. I was actually waiting for cmatrix to appear.
Thank you for this. It was really helpful and im sure its gonna help a lot of people from diferent levels.
Thank you coming from Cebu, Philippines.
deleting single words to the right of the cursor with ctrl+del or to the right with alt+backspace is also useful, same as navigating around whole words with ctrl+arrow
Nice tip! Thank you man!
In most terminals: CTRL-SHIFT-C to copy, CTRL-SHIFT-V to past.
It is annoying, but makes sense. CTRL-C is "COPY" in desktop applications. But it is the kill-process in the terminal.
I didn't know about 'column'. That's handy - especially in the specific example you gave. 'mount' is incredibly noisy (I usually use grep to filter).
Hi great video; if you add alias cmatrix='cmatrix -s' to .bash_aliases cmatrix will act like a screen saver i.e. any key subsequently pressed will exit cmatrix.
Hola Hermano! muy buenos tus videos, ¡muy bien explicados!. Greeting from Perú...😀
opposed to ctrl+a and ctrl+e to go to the start and end of a line i use the buttons home and end buttons abothe the arrows, its muscle memory and works (if not should) everywhere i can type text
Those keyboard shortcuts (cntrl-a, cntrl-e, cntrl-u, etc.) are Emacs shortcuts. Others work too - from next-word (ESC-f) to delete-to-EOL (cntrl-k), etc. If you use Emacs a lot, it's handy!
The cd - is incredibly useful when combined with fasd. For instance i can jump to a directory by doing z project, and then jump back again using cd - While cd .. is usefull for jumping back across time and space cd - is golden.
I expected you to include command || command to show that if the first command fails, run the second command.
@ - "Searching through command history" is actually an emacs keybinding for reverse search. You can use others too: c-a (go to beginning of a line) c-e (go to end) c-d (delete a char) etc.
For the vi folks like me.
In your bash terminal type
_set -o vi_
and you have vi key bindings
(e.g. _Esc / wget_ would search backwards in bash's history for your last wget command, hitting n would take you to the next and so forth)
Typing
_set +vi_ toggles back to the default emacs key bindings.
Learned some new tricks that I didnt know before. Great! Thanks.
Hello Sir, I am a noob system administrator and this helped a lot ❤️
For CD you can also use CD .. to move back down one level. Never knew about Ctrl+L.....Good tip.
great tools you show here and great that the community is adding their more than 2 cents. I like aliases, because I can nest an alias within an alias without ever calling it, and its also a pit fall of naming aliases...config push origin HEAD:master
cps -f origin master
these 2 commands let me reset my git bare repo to a new system, where config is '/usr/bin/git --git-dir=$HOME/bare/ --work-tree=$HOME', and then cps is config push, and this right here is where I used config as a previous alias in a new alias.
In one word: AMAZING
Very useful video for new to linux people like me. I have a doubt, what happens if we combine 3 commands with && sign? I tried alias upd="sudo apt update && sudo apt upgrade && sudo apt dist-upgrade" but seems 3rd command isnt working. When i run it without alias with the same syntax, those 3 works. So I dunno wats wrong.. If u can help pls..
Thanks in advance.
Thank you for these Tips. I am using Ubuntu, and I could not use Ctrl + Shift + +, to increase the font size, it doesn't take, is there another way to do it?
How do i find the boot time for my Linux Mint Uma using the terminal as I have a very slow boot time - in the vicinity of four minutes and can I change the boot time via the terminal command?
Thanks for the video J. I think you have mostly covered the commands I use in other videos.
Only piece of advice I can offer for the truncating files, if you want to erase a full file, you can run "> /var/log/syslog" as an example, it's a blank redirect that wipes the file clean, easier than truncate. You could add more with grep, less, tmux, wc, sed/awk, vim to the video and then it might be close to being the complete guide.
You can also use :var to temporarily leave the vim terminal, it should split the screen in two.
Thanks dude! You're an amazing guide.
Push and pop works like a stack , can we pop from the middle in some way?
This is really helpful. Thank you!
What is the command to check the memory usage of server at a particular time?
Awesome session !
nice, today is 28.10 and i watching this video on same day and month when this video was recorded. Point is - year does not matters
i like "cut" command. For example to extract one column of CSV file you can use it and redirect output to "result file". with grep you can "cut and filter" csv easy
earned a sub! love this
Genial amigo, espero sigas trayendo mas trucos y comando en el terminal.
On thing about the HISTTIMEFORMAT change in the config file is that I had to reload the terminal for it to work on Windows WSL
My fav that you didn’t mention is “less”, but that’s kinda its own program that you could do a whole video on.
When I make a typo in a command I like re-running it by typing ^typo^correction^. For example "mdir someDir" (oops). Now enter "^d^kd^" to get the intended "mkdir someDir".
Does Debian have a helper like yay from Arch? I find it so unproductive to use Debian for it, any advice would be welcome