I know it's been a while, and this is only a short one, but I wanted to get these down.
I've been experimenting with the command line strengths of Linux, combining commands to perform powerful statements. The first is:
find -name "*.JPG" -exec rename 's/\.JPG$/\.jpg/' {} \;
This command will find every file within a tree structure from the point the command is run that has .JPG as it's extension and then rename it to .jpg. Linux automatically recognises .jpg to be a picture but not .JPG. For someone like me with over 3000 pictures in numerous subdirectories this was a huge productivity help. It is simple to modify it for other file types too. Obvious ones spring to mind like .AVI, .BMP, .MPG etc.
Another thing I wanted to do was increase the rights on a tree structure for all files whilst removing execute. I know from painful past experience that chmod -R 0664 * has disastrous results with directories! However, combining find and chmod allowed me to produce these 2 commands:
find -type f -exec chmod 0664 {} \;
find -type d -exec chmod 2775 {} \;
The first only finds files and then changes the permissions to give the user and group read and write, allow everyone read, and removes execute across the board.
The second finds directories and changes the permissions as above (whilst allowing execute because they are directories), and also changes the permissions on the directory to ensure that every new file is given the group ownership of the directory, and not the user creating it.
As I continue to play with regular expressions and the command line I'm sure I'll find more of these gems. I'll probably put them here too.
For now, one more:
find -name "*.zip" -exec unzip -o {} \;
OK, one more:
rename 's/^\d+_//' *
This will remove the leading number and underscore from files or directories such as those that have been downloaded using .nzb files from newsgroups. Useful for tidying up your downloaded directory structure. (Or at least useful for tidying up mine!)
Me, Steve, spouting off about stuff that interests me. Probably techie, but not necessarily. Linux and google are a favourite, but life and general weirdness can be expected too.
Subscribe to:
Post Comments (Atom)
Top Tracks of 2012
Well, it's that time of year. Once again I can abuse my html knowledge and shove a few YouTube videos into a blog post to illustrate wha...
-
In answer to a request, today we ponder 2 of the trickiest questions ever asked: Are Bert and Ernie more than just friends? Why does bun...
-
So, first things first, today's weight: 12 st 0.4 lb. Down around 4 lb from yesterday. Good start. Should hit 11 st x tomorrow, and 10 s...
-
It's been a while! (Feb 24th fact fans), but I haven't had a lot to say. The diet thing was done, the daily minutiae is on twitter ,...
No comments:
Post a Comment