[Dorset] cd question
I am a cli dunce so please bear with me. Lets say I am working in the terminal screen in the following folder m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah blah. Now I want to go back to work in folder2, what the easy command to get me back there?? I have to move a lot of files (1 and 2) between a lot of folders and retyping the full path everytime is wearing my keyboard out!! Tim -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
> m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah blah. > > Now I want to go back to work in folder2, what the easy command to get me back > there?? Assuming you're working in folder5 in your example, running 'cd ..' will go back to folder4. To go down two levels, you want 'cd ../..' and for three, just add another '/..' I find it useful to remember that . is the current folder .. is the folder level before it. Fred. -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
Hi Tim, you can use '..' to tell cd to go one folder up from where you are currently in the folder hierarchy. So if you are at /home/tim/folder1/folder2/folder3/folder4/folder5 , then $ cd .. will put you into folder4 $ cd ../.. will put you into folder3 $ cd ../../.. will put you into folder2 $ cd ../../../.. will put you into folder1 If you are expecting to want to go back to folder5, you might find 'pushd' and popd' useful. pushd ../../.. will take you to folder2 but will also remember folder5 as your prevoius folder on a 'stack' and you can later, from folder2, say 'popd' to 'pop' the top folder from your stack so you will go back to folder5. Hope that helps, Victor -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 22/11/2010 18:16, StarLion wrote: >> m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah >> blah. >> >> Now I want to go back to work in folder2, what the easy command to get me >> back >> there?? > Assuming you're working in folder5 in your example, running 'cd ..' > will go back to folder4. > To go down two levels, you want 'cd ../..' and for three, just add another > '/..' > _ If you are using these regularly then you can also use aliases to create shortcuts to the directories (i.e. gowww is alised on my system to /home2/var/www/site1/ Alternatively you can use symlinks to create pointers to those directories, i.e. my /backup is a link to /media/nfs/buffnas1/backups/serverwww1 Si -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 22/11/10 18:05, Tim wrote: > I am a cli dunce so please bear with me. > > Lets say I am working in the terminal screen in the following folder > > m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah blah. > > Now I want to go back to work in folder2, what the easy command to get me > back > there?? > > I have to move a lot of files (1 and 2) between a lot of folders and retyping > the full path everytime is wearing my keyboard out!! Not necessarily applicable here, but if you are going back and forth between two directories 'cd -' will also do the trick, taking you pack to the last folder. So, cd into the first folder, then cd into the second. To get back to the first issue 'cd -', and once you are there the same command will take you back to the second, and so on. Sean -- music, film, comics, books, rants and drivel: www.funkygibbins.me.uk -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
Judicious use of symbolic links and bash regular expressions can also make short work of this. If you do cd ~/folder1/folder2/folder3/folder4/folder5 ln -s ../../.. folder2 you will have a folder under folder5 called folder2 which points to your original folder2 directory You can then simply mv filename folder2/ to move each file. Bash regular expressions can come in handy when moving lots (but not all) files. For example mv DSCF0[4-6]*.jpg will move everything between DSCF04... to DSCF06... with one statement. Google for more help, since I'm not too good with regular expressions, myself. Once you are done, you can run rm folder2 in folder5 to remove the symlink (but not the original directory). Note also that a symlink to a folder above your current location in the hierarchy does create an infinite loop, Be careful when using recursive commands! If it is likely that you are going to be moving things to folder2 regularly from a variety of location, you may want to create a bash script, which takes a filename as an argument: #!/bin/sh # moves a given filename to ~/folder1/folder2/ mv $1 ~/folder1/folder2/ Save this as folder2 in your home directory (or somewhere in your path: I use ~/bin/ which I add to path). Then run chmod 755 folder2 to make it executable. Then you can type folder2 filename to move filename from any directory to ~/folder1/folder2 Have fun! Marti On 22 November 2010 13:26, Simon P Smith wrote: > On 22/11/2010 18:16, StarLion wrote: > >> m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah > blah. > >> > >> Now I want to go back to work in folder2, what the easy command to get > me back > >> there?? > > Assuming you're working in folder5 in your example, running 'cd ..' > > will go back to folder4. > > To go down two levels, you want 'cd ../..' and for three, just add > another '/..' > > _ > If you are using these regularly then you can also use aliases to create > shortcuts to > the directories (i.e. gowww is alised on my system to /home2/var/www/site1/ > > Alternatively you can use symlinks to create pointers to those > directories, i.e. > my /backup is a link to /media/nfs/buffnas1/backups/serverwww1 > > Si > > -- > Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 > Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ > How to Report Bugs Effectively: http://goo.gl/4Xue > -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 22/11/10 18:05, Tim wrote: I am a cli dunce so please bear with me. Lets say I am working in the terminal screen in the following folder m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah blah. Now I want to go back to work in folder2, what the easy command to get me back there?? I have to move a lot of files (1 and 2) between a lot of folders and retyping the full path everytime is wearing my keyboard out!! All the other suggestions are excellent, but let's have some more ;) You could use shell variables to remember the paths: src=/folder1/folder2/folder3/folder4/folder5 dst=/folder1/folder2 Then use cd "$src" and cd "$dst" as required, or mv somefile "$dst" (The quotes stop things breaking if the paths have spaces in them.) Or, how about doing (in folder5):- ls > files vim files (OR nano files, OR gedit files, as you prefer) Delete the ones you don't want to move, then save the file and: dest=/folder1/folder2; while read -r file; do mv "$file" "$dest"; done < files (That's all on one line but it may wrap here) That should do a move for each filename, one per line, in "files". Another way is with find, if the files have some criteria you can define. Find has a lot of options, and can be a bit daunting, but a good pattern to remember is:- find [] [] [] The default path is "." and the default action is "print", so just typing "find" will recursively list files in the current directory and subdirectories. For example, find -mtime -1 -maxdepth 1 Will print file names of files modified more recently than 24 hours ago in this directory only (will not go into subdirectories). There are many ways to use this. You could do:- find -mtime -2 -iname 'foo*' > files To send all files modified in the last two days matching foo* to a file called "files", and then use the mechanism above. Another way is to use the pattern:- find -exec '{}' \; That's a bit odd looking, but gets executed for each file found, replacing '{}' with the name. For example:- find -mtime -2 -iname 'foo*' -exec mv '{}' /folder1/folder2 (The first time, you may want to do.. find -mtime -2 -iname 'foo*' -exec echo mv '{}' /folder1/folder2 ) (You can probably stop here if this is getting too much, or have a cup of tea and come back ... ) You can also use xargs, which takes files on the standard input and executes a command, passing them as arguments to it. There are ways to control what to do if nothing is passed, or how many arguments at once the command can take. See man xargs for more. Here's an example:- find -mtime -2 -iname 'foo*' | xargs rm -i This will delete all files that find matches. It's easy if you want all the files chained onto the end of the command, but you don't so you have to use another option for xargs:- find -mtime -2 -iname 'foo*' | xargs -I '{}' mv '{}' /folder1/folder2 Here, -I specifies some arbitrary string which gets replaced with the items being fed into xargs. There's one more strange thing you might see, and that is to avoid the fact that here files are 1 per line, but it is technically possible for a filename to contain a line break. You can make find spit things out separated with a NULL character instead, and tell xargs to expect this. find -mtime -2 -iname 'foo*' -print0 | xargs -0 -I '{}' mv '{}' /folder1/folder2 One last bit of polish:- find -mtime -2 -iname 'foo*' -print0 | xargs --no-run-if-empty -0 -I '{}' mv '{}' /folder1/folder2 That's probably self-explanatory. I know the above look a bit odd at first, but I found I'd learn them one "formula" at a time and each time I needed to do something different, I'd learn a variation, and so on. Have fun! -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
Sheesh! Seconds after posting, I spot my deliberate mistakes... On 22/11/10 19:30, John Carlyle-Clarke wrote: That's a bit odd looking, but gets executed for each file found, replacing '{}' with the name. For example:- find -mtime -2 -iname 'foo*' -exec mv '{}' /folder1/folder2 (The first time, you may want to do.. find -mtime -2 -iname 'foo*' -exec echo mv '{}' /folder1/folder2 ) That should be:- find -mtime -2 -iname 'foo*' -exec mv '{}' /folder1/folder2 \; find -mtime -2 -iname 'foo*' -exec echo mv '{}' /folder1/folder2 \; (In other words, \; was missing off the end) -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On Mon, 2010-11-22 at 19:30 +, John Carlyle-Clarke wrote: > On 22/11/10 18:05, Tim wrote: > > > > I am a cli dunce so please bear with me. > > > > Lets say I am working in the terminal screen in the following folder > > > > m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah > > blah. > > > > Now I want to go back to work in folder2, what the easy command to get me > > back > > there?? > > > > I have to move a lot of files (1 and 2) between a lot of folders and > > retyping > > the full path everytime is wearing my keyboard out!! > > > > All the other suggestions are excellent, but let's have some more ;) > > You could use shell variables to remember the paths: > > src=/folder1/folder2/folder3/folder4/folder5 > dst=/folder1/folder2 > > Then use cd "$src" and cd "$dst" as required, or mv somefile "$dst" > > (The quotes stop things breaking if the paths have spaces in them.) > > Or, how about doing (in folder5):- > > ls > files > vim files > (OR nano files, OR gedit files, as you prefer) > > Delete the ones you don't want to move, then save the file and: > > dest=/folder1/folder2; while read -r file; do mv "$file" "$dest"; done < > files > > (That's all on one line but it may wrap here) > > That should do a move for each filename, one per line, in "files". > > Another way is with find, if the files have some criteria you can > define. Find has a lot of options, and can be a bit daunting, but a > good pattern to remember is:- > > find [] [] [] > > The default path is "." and the default action is "print", so just > typing "find" will recursively list files in the current directory and > subdirectories. > > For example, > > find -mtime -1 -maxdepth 1 > > Will print file names of files modified more recently than 24 hours ago > in this directory only (will not go into subdirectories). > > There are many ways to use this. You could do:- > > find -mtime -2 -iname 'foo*' > files > > To send all files modified in the last two days matching foo* to a file > called "files", and then use the mechanism above. > > Another way is to use the pattern:- > > find -exec '{}' \; > > That's a bit odd looking, but gets executed for each file > found, replacing '{}' with the name. For example:- > > find -mtime -2 -iname 'foo*' -exec mv '{}' /folder1/folder2 > > (The first time, you may want to do.. > > find -mtime -2 -iname 'foo*' -exec echo mv '{}' /folder1/folder2 > > ) > > (You can probably stop here if this is getting too much, or have a cup > of tea and come back ... ) > > You can also use xargs, which takes files on the standard input and > executes a command, passing them as arguments to it. There are ways to > control what to do if nothing is passed, or how many arguments at once > the command can take. See man xargs for more. > > Here's an example:- > > find -mtime -2 -iname 'foo*' | xargs rm -i > > This will delete all files that find matches. It's easy if you want all > the files chained onto the end of the command, but you don't so you have > to use another option for xargs:- > > find -mtime -2 -iname 'foo*' | xargs -I '{}' mv '{}' /folder1/folder2 > > Here, -I specifies some arbitrary string which gets replaced with the > items being fed into xargs. > > There's one more strange thing you might see, and that is to avoid the > fact that here files are 1 per line, but it is technically possible for > a filename to contain a line break. You can make find spit things out > separated with a NULL character instead, and tell xargs to expect this. > > find -mtime -2 -iname 'foo*' -print0 | xargs -0 -I '{}' mv '{}' > /folder1/folder2 > > One last bit of polish:- > > find -mtime -2 -iname 'foo*' -print0 | xargs --no-run-if-empty -0 -I > '{}' mv '{}' /folder1/folder2 > > That's probably self-explanatory. > > I know the above look a bit odd at first, but I found I'd learn them one > "formula" at a time and each time I needed to do something different, > I'd learn a variation, and so on. > > Have fun! > And my wife complains that under MS Windows there are so many ways to do things and why couldn't they just have one way to do it. I am lazy. From the terminal I would just type in 'sudo dolphin' and split the display to move them. Peter -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 22 November 2010 20:56, Peter Merchant wrote: > > And my wife complains that under MS Windows there are so many ways to do > things and why couldn't they just have one way to do it. > > > I am lazy. From the terminal I would just type in 'sudo dolphin' and > split the display to move them. > > Watch out, you'll get me started about emacs ;-) -- best regards, Victor Churchill, Bournemouth -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On Monday 22 November 2010 20:56:34 Peter Merchant wrote: > On Mon, 2010-11-22 at 19:30 +, John Carlyle-Clarke wrote: > > On 22/11/10 18:05, Tim wrote: > > > I am a cli dunce so please bear with me. > > > > > > Lets say I am working in the terminal screen in the following folder > > > > > > m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah > > > blah. > > > > > > Now I want to go back to work in folder2, what the easy command to get > > > me back there?? > > > > > > I have to move a lot of files (1 and 2) between a lot of folders and > > > retyping the full path everytime is wearing my keyboard out!! > > > > All the other suggestions are excellent, but let's have some more ;) > > > > You could use shell variables to remember the paths: > > > > src=/folder1/folder2/folder3/folder4/folder5 > > dst=/folder1/folder2 > > > > Then use cd "$src" and cd "$dst" as required, or mv somefile "$dst" > > > > (The quotes stop things breaking if the paths have spaces in them.) > > > > Or, how about doing (in folder5):- > > > > ls > files > > vim files > > (OR nano files, OR gedit files, as you prefer) > > > > Delete the ones you don't want to move, then save the file and: > > > > dest=/folder1/folder2; while read -r file; do mv "$file" "$dest"; done < > > files > > > > (That's all on one line but it may wrap here) > > > > That should do a move for each filename, one per line, in "files". > > > > Another way is with find, if the files have some criteria you can > > define. Find has a lot of options, and can be a bit daunting, but a > > good pattern to remember is:- > > > > find [] [] [] > > > > The default path is "." and the default action is "print", so just > > typing "find" will recursively list files in the current directory and > > subdirectories. > > > > For example, > > > > find -mtime -1 -maxdepth 1 > > > > Will print file names of files modified more recently than 24 hours ago > > in this directory only (will not go into subdirectories). > > > > There are many ways to use this. You could do:- > > > > find -mtime -2 -iname 'foo*' > files > > > > To send all files modified in the last two days matching foo* to a file > > called "files", and then use the mechanism above. > > > > Another way is to use the pattern:- > > > > find -exec '{}' \; > > > > That's a bit odd looking, but gets executed for each file > > found, replacing '{}' with the name. For example:- > > > > find -mtime -2 -iname 'foo*' -exec mv '{}' /folder1/folder2 > > > > (The first time, you may want to do.. > > > > find -mtime -2 -iname 'foo*' -exec echo mv '{}' /folder1/folder2 > > > > ) > > > > (You can probably stop here if this is getting too much, or have a cup > > of tea and come back ... ) > > > > You can also use xargs, which takes files on the standard input and > > executes a command, passing them as arguments to it. There are ways to > > control what to do if nothing is passed, or how many arguments at once > > the command can take. See man xargs for more. > > > > Here's an example:- > > > > find -mtime -2 -iname 'foo*' | xargs rm -i > > > > This will delete all files that find matches. It's easy if you want all > > the files chained onto the end of the command, but you don't so you have > > to use another option for xargs:- > > > > find -mtime -2 -iname 'foo*' | xargs -I '{}' mv '{}' /folder1/folder2 > > > > Here, -I specifies some arbitrary string which gets replaced with the > > items being fed into xargs. > > > > There's one more strange thing you might see, and that is to avoid the > > fact that here files are 1 per line, but it is technically possible for > > a filename to contain a line break. You can make find spit things out > > separated with a NULL character instead, and tell xargs to expect this. > > > > find -mtime -2 -iname 'foo*' -print0 | xargs -0 -I '{}' mv '{}' > > /folder1/folder2 > > > > One last bit of polish:- > > > > find -mtime -2 -iname 'foo*' -print0 | xargs --no-run-if-empty -0 -I > > '{}' mv '{}' /folder1/folder2 > > > > That's probably self-explanatory. > > > > I know the above look a bit odd at first, but I found I'd learn them one > > "formula" at a time and each time I needed to do something different, > > I'd learn a variation, and so on. > > > > Have fun! > > And my wife complains that under MS Windows there are so many ways to do > things and why couldn't they just have one way to do it. > > > I am lazy. From the terminal I would just type in 'sudo dolphin' and > split the display to move them. > > > Peter Thanks for all the info guys, I managed with the cd ../.. method but if I was doing this on a frequent basis I would try some of the more automated ways. I did try the gui route but for some reason copy and pasted failed to work. Tim -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 22/11/10 18:05, Tim wrote: I am a cli dunce so please bear with me. Lets say I am working in the terminal screen in the following folder m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah blah. Now I want to go back to work in folder2, what the easy command to get me back there?? I have to move a lot of files (1 and 2) between a lot of folders and retyping the full path everytime is wearing my keyboard out!! Assuming you are using bash shell, add a function to move to the directory you want in an easy command like cd1 Edit .bash_profile $ cd $ vi .bash_profile Add function cd1() { cd /tmp;pwd } Save and exit $ source .bash_profile Now you can use cd1 to get you to /tmp or whatever folder/path you want. Add as many functions as you need. -- -- Discover Linux - Open Source Solutions to Business and Schools http://discoverlinux.co.uk -- -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On Mon, 2010-11-22 at 22:51 +, Victor Churchill wrote: > On 22 November 2010 20:56, Peter Merchant wrote: > > > > > And my wife complains that under MS Windows there are so many ways to do > > things and why couldn't they just have one way to do it. > > > > > > I am lazy. From the terminal I would just type in 'sudo dolphin' and > > split the display to move them. > > > > Watch out, you'll get me started about emacs ;-) > I remember using emacs on the PT-121(?) terminals at Plessey. I think I threw out the user guide for it about a year ago. PM -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 22/11/10 18:05, Tim wrote: I am a cli dunce so please bear with me. Lets say I am working in the terminal screen in the following folder m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah blah. Now I want to go back to work in folder2, what the easy command to get me back there?? I have to move a lot of files (1 and 2) between a lot of folders and retyping the full path everytime is wearing my keyboard out!! I use MidnightCommander (aka mc) for that sort of thing. See http://www.midnight-commander.org/ Install with aptitude install mc or equivalent. cheers Chris -- Chris Dennis cgden...@btinternet.com Fordingbridge, Hampshire, UK -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On Monday 22 November 2010, Peter Merchant wrote: > On Mon, 2010-11-22 at 19:30 +, John Carlyle-Clarke wrote: > > On 22/11/10 18:05, Tim wrote: > > > I am a cli dunce so please bear with me. > > > > > > Lets say I am working in the terminal screen in the following folder > > > > > > m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah > > > blah. > > > > > > Now I want to go back to work in folder2, what the easy command to get > > > me back there?? > > > > > > I have to move a lot of files (1 and 2) between a lot of folders and > > > retyping the full path everytime is wearing my keyboard out!! > > > > All the other suggestions are excellent, but let's have some more ;) > > > > You could use shell variables to remember the paths: > > > > src=/folder1/folder2/folder3/folder4/folder5 > > dst=/folder1/folder2 > > > > Then use cd "$src" and cd "$dst" as required, or mv somefile "$dst" > > > > (The quotes stop things breaking if the paths have spaces in them.) > > > > Or, how about doing (in folder5):- > > > > ls > files > > vim files > > (OR nano files, OR gedit files, as you prefer) > > > > Delete the ones you don't want to move, then save the file and: > > > > dest=/folder1/folder2; while read -r file; do mv "$file" "$dest"; done < > > files > > > > (That's all on one line but it may wrap here) > > > > That should do a move for each filename, one per line, in "files". > > > > Another way is with find, if the files have some criteria you can > > define. Find has a lot of options, and can be a bit daunting, but a > > good pattern to remember is:- > > > > find [] [] [] > > > > The default path is "." and the default action is "print", so just > > typing "find" will recursively list files in the current directory and > > subdirectories. > > > > For example, > > > > find -mtime -1 -maxdepth 1 > > > > Will print file names of files modified more recently than 24 hours ago > > in this directory only (will not go into subdirectories). > > > > There are many ways to use this. You could do:- > > > > find -mtime -2 -iname 'foo*' > files > > > > To send all files modified in the last two days matching foo* to a file > > called "files", and then use the mechanism above. > > > > Another way is to use the pattern:- > > > > find -exec '{}' \; > > > > That's a bit odd looking, but gets executed for each file > > found, replacing '{}' with the name. For example:- > > > > find -mtime -2 -iname 'foo*' -exec mv '{}' /folder1/folder2 > > > > (The first time, you may want to do.. > > > > find -mtime -2 -iname 'foo*' -exec echo mv '{}' /folder1/folder2 > > > > ) > > > > (You can probably stop here if this is getting too much, or have a cup > > of tea and come back ... ) > > > > You can also use xargs, which takes files on the standard input and > > executes a command, passing them as arguments to it. There are ways to > > control what to do if nothing is passed, or how many arguments at once > > the command can take. See man xargs for more. > > > > Here's an example:- > > > > find -mtime -2 -iname 'foo*' | xargs rm -i > > > > This will delete all files that find matches. It's easy if you want all > > the files chained onto the end of the command, but you don't so you have > > to use another option for xargs:- > > > > find -mtime -2 -iname 'foo*' | xargs -I '{}' mv '{}' /folder1/folder2 > > > > Here, -I specifies some arbitrary string which gets replaced with the > > items being fed into xargs. > > > > There's one more strange thing you might see, and that is to avoid the > > fact that here files are 1 per line, but it is technically possible for > > a filename to contain a line break. You can make find spit things out > > separated with a NULL character instead, and tell xargs to expect this. > > > > find -mtime -2 -iname 'foo*' -print0 | xargs -0 -I '{}' mv '{}' > > /folder1/folder2 > > > > One last bit of polish:- > > > > find -mtime -2 -iname 'foo*' -print0 | xargs --no-run-if-empty -0 -I > > '{}' mv '{}' /folder1/folder2 > > > > That's probably self-explanatory. > > > > I know the above look a bit odd at first, but I found I'd learn them one > > "formula" at a time and each time I needed to do something different, > > I'd learn a variation, and so on. > > > > Have fun! > > And my wife complains that under MS Windows there are so many ways to do > things and why couldn't they just have one way to do it. > > > I am lazy. From the terminal I would just type in 'sudo dolphin' and > split the display to move them. > > > Peter > > > > > > > > -- > Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 > Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ > How to Report Bugs Effectively: http://goo.gl/4Xue As an old time UNIX cli man thats exactly what I would have done! Its exactly what they invented drag'n'drop for :) -- Andy Paterson -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Mee
Re: [Dorset] cd question
On Tuesday 23 November 2010, Peter Merchant wrote: > On Mon, 2010-11-22 at 22:51 +, Victor Churchill wrote: > > On 22 November 2010 20:56, Peter Merchant wrote: > > > And my wife complains that under MS Windows there are so many ways to > > > do things and why couldn't they just have one way to do it. > > > > > > > > > I am lazy. From the terminal I would just type in 'sudo dolphin' and > > > split the display to move them. > > > > > > Watch out, you'll get me started about emacs ;-) > > I remember using emacs on the PT-121(?) terminals at Plessey. I think I > threw out the user guide for it about a year ago. > > PM > > > -- > Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 > Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ > How to Report Bugs Effectively: http://goo.gl/4Xue HOWEVER! I recently worked somewhere where we had to access masses of servers throughout the country over the internet (some vpn - some not) and I can tell you that a simple telnet/netterm tty login was the _only_ way and it was VERY effective - particularily when logging in via a terminal concentrator to reboot something like a sun server (i.e console only access) . So there is a LOT of life left in in tty (CLI) only access yet! -- Andy Paterson -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On Tue, 23 Nov 2010 19:16:54 +, andy.pater...@ntlworld.com said: > So there is a LOT of life left in in tty (CLI) only access yet! Absolutely. At work, we support and work on a large number of Linux servers around the country, and none of them has a GUI: everything done by the command line (and some distributed management tools). -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
On 23/11/10 19:08, Andrew R Paterson wrote: ---8<--- Snip! > On Monday 22 November 2010, Peter Merchant wrote: >> >> And my wife complains that under MS Windows there are so many ways to do >> things and why couldn't they just have one way to do it. >> >> >> I am lazy. From the terminal I would just type in 'sudo dolphin' and >> split the display to move them. > As an old time UNIX cli man thats exactly what I would have done! > Its exactly what they invented drag'n'drop for :) There, doesn't that look better? :-) Sean -- music, film, comics, books, rants and drivel: www.funkygibbins.me.uk -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
Hi Martin, > Bash regular expressions can come in handy when moving lots (but not > all) files. For example > > mv DSCF0[4-6]*.jpg will move everything between DSCF04... to DSCF06... > with one statement. Strictly speaking those are not regular expressions. Their historic name is "glob" patterns, after the program, glob(1), that used to expand them. (That was back before the shell understood them.) Classic globbing gives * to mean zero or more characters, ? to mean exactly one character, and [] to indicate a set of characters with a leading ! negating that set, e.g. foo_?*_14[:.]20[:.]??[!.] And a leading * doesn't match directory entries beginning with ".". Because there's no way of specifying general alternation, or that a chunk of the pattern can be repeated zero or more times, they don't have the power of regular expressions. E.g. in the above example I've said that the last character mustn't be a dot but I can't make it optional as well whereas I can with the extended regular expression ^foo_.+_14[:.]20[:.]..[^.]?$ Cheers, Ralph. -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
Hi John Carlyle-Clarke wrote: > > I am a cli dunce so please bear with me. Ignoring all the cheats that just used the command line to start a GUI, sometimes as root!... :-) > > m...@computer:~#/folder1/folder2/folder3/folder4/folder5 mv blah > > blah. > > > > Now I want to go back to work in folder2, what the easy command to > > get me back there?? Are you aware of the shell's filename completion with the Tab key? After typing cd /fo pressing Tab may well complete more of the path for you because there's only one unique choice, e.g. cd /folder will now be present leaving you to enter the "1". If Tab can't complete any more then it will beep. Pressing it again may make it list the alternatives. (This varies between shells and can be tailored too so I can't be specific.) If I'm hopping about or referring to places I'll use shell variables. (An alias to change directory gives me only that.) An easy way to set them is cd /some/long/path d=`pwd` # Note, these are backticks. ... cd $d ... mv *.c $d although annoyingly you'll have to wrap the definition of d and all uses of it with "" if the path includes a space. Don't put spaces into directory or file names! :-) Plan 9 banned them in the kernel, wisely. cd /some/long/really stupid/path d="`pwd`" ... cd "$d" ... mv *.c "$d" If I have a big bunch of files in the current directory and want to spread them around other directories without an obvious pattern, e.g. in filename or content, then I'd go into vi, do !!ls to get the list of files, one per line, and then edit up the file until it was a bunch of mv invocations, one per line. Perhaps put a `set -e' at the beginning and then do gg!Gsh to run the whole lot of lines through a shell. If all the lines disappear there were no errors. > Another way is to use the pattern:- > > find -exec '{}' \; > > That's a bit odd looking, but gets executed for each file > found, replacing '{}' with the name. The braces don't need quoting, saving some fiddly typing, as shells don't perform brace expansion on an empty {}. Probably due to find's use of them pre-dating the C shell's introduction of brace expansion. Cheers, Ralph. -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] cd question
Hi On 25/11/10 14:14, Ralph Corderoy wrote: Are you aware of the shell's filename completion with the Tab key? After typing cd /fo Apologies if already mentioned, but the key sequence I probably use most in bash is crtl-r followed by some part of a previously entered command. Bash searches back through history for matches - can then hit enter, or modify the found command and then hit enter. Cheers Tim -- Next meeting: Somewhere quiet, Bournemouth, ???day 2010-12-?? 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue