File Globbing In Linux

  Рет қаралды 23,035

DistroTube

DistroTube

Күн бұрын

Пікірлер: 64
@Zellonous
@Zellonous 4 жыл бұрын
Back in the good old days, my parents got a computer. I think it was their first personal computer. my mom accidentally copied a chess game over a DOS install so whenever the pc booted it would run the chess game. She did some "copy *.*" command. It prompted my dad to become somewhat of a DOS guru so he could fix it. So because of this, I've known about wildcards and the dangers of haphazard commands since I can remember xD
@Phydoux2112
@Phydoux2112 4 жыл бұрын
My first introduction to the * was with the Commodore 64. LOAD"*",8,1 which loaded the first file on the disk. Oh, how far I've come from the Commodore 64 to installing a hard drive on a Commodore 64, to DOS, to Windows, and finally to Arch Linux. It's been a bumpy ride these last 40 or so years. But it's been a lot of fun. I've enjoyed the evolution of computers on my end.
@jaiden91
@jaiden91 4 жыл бұрын
touch file{1..10}.txt :)
@DistroTube
@DistroTube 4 жыл бұрын
Was waiting for someone to mention this. Surprised it took so long. ;)
@Khyree_Holmes
@Khyree_Holmes 4 жыл бұрын
hey! I tried to do that, brain fart.... got it now.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
Sometimes you need to feed the files to a command one at a time. This works with bash: for i in {1..10}; do echo file${i}.txt; done Sometimes you need leading zeroes on the numbers. This also works with bash: for i in {01..10}; do echo file${i}.txt; done If you are using a more minimal shell (e.g. dash) that doesn’t do “{..}” pattern expansion, there is always the “seq” command: for i in $(seq 1 10); do echo file${i}.txt ; done If you want the leading zeroes, seq won’t do them, so try the “printf” command: for i in $(seq 1 10); do echo file$(printf %02d ${i}).txt ; done
@dkosmari
@dkosmari 4 жыл бұрын
Maybe for next video, bash variable evaluation witchcraft.
@dingokidneys
@dingokidneys 4 жыл бұрын
@@kirschkern8260 This is not actually copy/paste. Many terminals though (not shells) do have a copy/paste function . E.g. Terminator (and some others) use Ctrl+Shift+c and Ctrl+Shift+v to copy and paste. Just highlight with the mouse cursor and off you go. Sometimes you can just highlight text in the terminal then right click and it will be pasted onto the command line. Useful.
@BrucesWorldofStuff
@BrucesWorldofStuff 4 жыл бұрын
Nothing like Globbing to get some work done.. It is strange the names that Linux folks come up with... I just go with it as it is really neat! Thanks DT for the video! LLAP
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
The name dates from UNIX. Linux inherited a lot of old UNIX culture.
@fredhair
@fredhair 4 жыл бұрын
Asterix symbol? What about the Obelix symbol?
@fredhair
@fredhair 4 жыл бұрын
@@peterjansen4826 Me too, I know the books are available over there but not sure if they're popular. I'm in the UK and love them :)
@The_Penguin_City
@The_Penguin_City 2 жыл бұрын
Caius Trolebus symbol too.
@berndeckenfels
@berndeckenfels 4 жыл бұрын
You should mention the "echo test?.txt" trick to check what the pattern matches. Also backslash as a escape and single quotes to turn globing off
@d_rooster
@d_rooster 4 жыл бұрын
Hey man, thanks for all the awesome videos. I'm learning Linux again!
@AnzanHoshinRoshi
@AnzanHoshinRoshi 4 жыл бұрын
Thank you, Derek. Good stuff.
@surferbum618
@surferbum618 4 жыл бұрын
Thanks for all you do DT
@shady4tv
@shady4tv 4 жыл бұрын
1:55 touch file{1..10}.txt you can iterate to 10 and make bash do the work for you! typing that long touch command is a chore.
@TrouvatkiDePercusion
@TrouvatkiDePercusion 4 жыл бұрын
I was wondering why he would do it the long way.
@___9136
@___9136 4 жыл бұрын
I didn't know that you can use ! instead of ^. ^ still seems preferable to me because it's exactly the same syntax that will be needed when later learning regexps. I understand why you might avoid getting into the translation between globbing/shell patterns, but I think the basic rules can be summarized pretty succinctly: '*' in glob translates to '.*' ('any character' + '0 or more of') in regexp '?' in glob translates to '.' ('any character'; without the '0 or more of' modifier, this matches exactly 1 character) '[...]' in glob translates to .. exactly the same in regexp (with some exceptions relating mainly to the use of backslashes) '[!...]' or '[^...]' in glob is as stated above, '[^...]' in regexp . , (, ), $, ^ in glob (outside of a character class) should be prefixed with a backslash for regexp One other thing I think maybe should be mentioned is that the subject you actually covered was _POSIX_ file globbing ('sh' / 'bash' without the 'extglob' option set), and other shells may have more (zsh, bash _with_ the extglob option set) or less (fish) sophisticated globbing available.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
“!” being POSIX is more likely to be supported by other shells besides Bash.
@___9136
@___9136 4 жыл бұрын
@@lawrencedoliveiro9104 I didn't know that. Testing a little, I can see that 'dash' supports only !. bash supports ^ and ! in both its normal and 'pretending to be sh' instances. 'ksh' supports ! and ^. tcsh supports only ^, not ! (! produces an 'event not found' error)
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
@@___9136 dash seems to be a good, minimal, POSIX-compliant shell. Nobody should be using tcsh or csh-derivative shells any more.
@___9136
@___9136 4 жыл бұрын
@@lawrencedoliveiro9104 I don't disagree (most of these I installed only for testing), but I do feel obligated to point out that the fact that tcsh was in Arch's community repo indicates that a minimum of 1000 people are in fact using it.
@mohammedhattab4594
@mohammedhattab4594 2 жыл бұрын
Great quality content!!
@brianstrong8841
@brianstrong8841 4 жыл бұрын
that was great
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
7:10 If you want to use regexes to match file names, you can do so with the “find” command. That’s a very useful command, by the way; worth doing an episode on, I think.
@___9136
@___9136 4 жыл бұрын
It's a very indepth command. The simplified finder `fd` has mostly replaced find, for me. Much easier to, for example, get files with one of several acceptable extensions (eg. png,jpg,gif)
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
I use “find -exec” all the time.
@___9136
@___9136 4 жыл бұрын
@@lawrencedoliveiro9104 Fair enough. I usually pipe to xargs unless I really need something sophisticated.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
@@___9136 That’s for acting on the results of the find. -exec is useful for applying a custom filter.
@ovieoyegwa6153
@ovieoyegwa6153 4 жыл бұрын
i followed through. thanks
@DJ_Cthulhu
@DJ_Cthulhu 4 жыл бұрын
I'm a glob denier, flat erf rulez 😏
@primokorn1
@primokorn1 Жыл бұрын
Great video. So file globbing is the same as regular expressions. It would be appreciated to have the shell in full screen 👍 not very easy to follow on my phone. Thank you.
@1yaz
@1yaz 4 жыл бұрын
Fun fact: GNU grep can be used to express regular languages, but not all grep regexes express regular languages.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
Hint: the “reg” in “regex” is short for for “regular”.
@Arkayaplays
@Arkayaplays 4 жыл бұрын
Hey #distrotube would you please take a look on Extern Os( i just found that based on ubuntu but they haven't mention on any where on there page.) quite confusing Os(at least i think)
@a13xhackintosh
@a13xhackintosh 3 жыл бұрын
This is a topic I failed in interview lol 😂😆😂😆😂
@Khyree_Holmes
@Khyree_Holmes 4 жыл бұрын
Something to throw in my Hat about Linux.
@sumanthcheedepudi8751
@sumanthcheedepudi8751 3 жыл бұрын
how to use globbing to list all the folders whose name doesn't contain a specific character. I tried this: LS *[!a]* ,which is not working.
@The_Penguin_City
@The_Penguin_City 2 жыл бұрын
Shopt -s extglob and exdot make you able to use glob characters if you can't.
@AliensInc.
@AliensInc. 4 жыл бұрын
@DistroTube!! You got any link for a good video about just RegExp? I read alot even seen some vids and still got real problems handling this.
@lilxghostt
@lilxghostt 3 жыл бұрын
I wish you where my Linux teacher
@michalroesler
@michalroesler 2 жыл бұрын
I wanna learn this new skill.
@lerrz8969
@lerrz8969 4 жыл бұрын
how bout display all files in the current directory that begins with test, only has 5 characters and does not have a 1,5,7 as the last character
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
As an exercise, how would you write a wildcard to match dotfiles in your home directory? These are the various files/directories containing user preferences for apps that you run. Their names begin with a dot, so they are normally excluded from directory listings. However, if you type something like “ls -ld ~/.*”, it will also show the useless “.” and “..” entries that clutter every Unix/Linux directory. How do you exclude these? The answer is: ls -ld ~/.[!.]*
@serge5046
@serge5046 4 жыл бұрын
There is even a simpler solution for it: just use the -A option of ls
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
@@serge5046 That won’t work if you just want directories, though: du -ks ~/.[!.]*/
@The_Penguin_City
@The_Penguin_City 2 жыл бұрын
Shopt -s dotglob
@robertcatesby4800
@robertcatesby4800 4 жыл бұрын
What's the command for restoring the deleted .txt test files?
@DistroTube
@DistroTube 4 жыл бұрын
There isn't an undo command. You simply create them again. I just created a bunch of empty files with touch: touch file1.txt file2.txt etc etc ... Because the names are so similar, something like the following works: touch file{1..10}.txt
@robertcatesby4800
@robertcatesby4800 4 жыл бұрын
Thanks. That's a cool one for the toolbox.
@TimothyEdgin
@TimothyEdgin 4 жыл бұрын
I love the Matrix screensaver but stopped using them when I caught a trojan in one; know where I can get one that is clean? Thanks for the refresh on globs.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
I like to use the xscreensaver package: packages.debian.org/buster/xscreensaver
@Tout-Le-Monde02
@Tout-Le-Monde02 4 жыл бұрын
Is that a Hugo project folder? Saw the config.toml file
@DistroTube
@DistroTube 4 жыл бұрын
Yea, just copied my hugo directory into that test directory.
@SuperWolfkin
@SuperWolfkin 4 жыл бұрын
I mean why not just use commands like >ls file[0-9].txt it would show what's being filtered without you needing to remove files and retouch them.
@subbus-g
@subbus-g 3 жыл бұрын
yeah, that's great. Also by using ls some_pattern before rm some_pattern we can ensure by seeing what files we are going to delete
@optimalcomrad
@optimalcomrad 4 жыл бұрын
First
@DistroTube
@DistroTube 4 жыл бұрын
It's official.
@lescitrons
@lescitrons 4 жыл бұрын
e
@nerrufam7105
@nerrufam7105 4 жыл бұрын
The 'g' in "RegEx" is pronounced the same as the 'g' in "Regular"
@lawrencedoliveiro9104
@lawrencedoliveiro9104 4 жыл бұрын
That’s not the way I pronounce it.
Terminal Commands Lesson 01 - pwd, cd, ls, man, --help
14:00
DistroTube
Рет қаралды 7 М.
60 Linux Commands you NEED to know (in 10 minutes)
10:50
NetworkChuck
Рет қаралды 1,5 МЛН
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26
小丑和白天使的比试。#天使 #小丑 #超人不会飞
00:51
超人不会飞
Рет қаралды 43 МЛН
Bend The Impossible Bar Win $1,000
00:57
Stokes Twins
Рет қаралды 47 МЛН
Find And Locate Your Files
10:55
DistroTube
Рет қаралды 15 М.
Two Powerful Command Line Utilities 'cut' And 'tr'
15:18
DistroTube
Рет қаралды 33 М.
Let's Share Our Favorite Bash Aliases
16:28
DistroTube
Рет қаралды 31 М.
Rust Programs Every Linux User Should Know About
13:18
DistroTube
Рет қаралды 135 М.
How To Use The Shell Commands 'pushd', 'popd' and 'dirs'
13:45
DistroTube
Рет қаралды 16 М.
Demystifying "find" and "find -exec" ...Lil' Linux Lesson!
8:12
Veronica Explains
Рет қаралды 49 М.
Xargs Should Be In Your Command Line Toolbag
16:24
DistroTube
Рет қаралды 99 М.
Linux Crash Course - Bash History
14:32
Learn Linux TV
Рет қаралды 14 М.
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26