Sometimes I forget the name of a particular config file but know it's stored as a dot file in my home directory. The following one-liner will non-recursively display any regular file begining with a dot.
find . -maxdepth 1 -type f -name '.*'
Find does it again. ;-)
Showing posts with label files. Show all posts
Showing posts with label files. Show all posts
Tuesday, December 2, 2008
Wednesday, August 13, 2008
Change Permissions on All Directories
Sometimes I need to recursively set permissions on all directories in a file hierarchy. Other times, I just want to set file permissions while ignoring directories. Fortunately, the find command makes this easy.
# make all directories read, write, execute for owner. read, execute for group and other
find . -type d -exec chmod 755 {} \;
# make all files read, write for owner. read for group and other
find . -type f -exec chmod 644 {} \;
# make all shell scripts read, write, execute for owner. read, execute for group and other
find . -type f -name "*.sh" 755 {} \;
# make all directories read, write, execute for owner. read, execute for group and other
find . -type d -exec chmod 755 {} \;
# make all files read, write for owner. read for group and other
find . -type f -exec chmod 644 {} \;
# make all shell scripts read, write, execute for owner. read, execute for group and other
find . -type f -name "*.sh" 755 {} \;
Monday, August 11, 2008
SVN: Add All New Files
I've been doing a lot of Ruby on Rails dev work lately, and the framework tends to generate a lot of files. Until recently, I was using a combination of "svn status" piped into grep, awk, and xargs to accomplish adding new files recursively. A friend recently told me to check out the following solution instead.
svn --force add *
The only negative side effect I can see is that it seems to add ignored files back into the tree. This is mostly a non-issue for me, but take note.
svn --force add *
The only negative side effect I can see is that it seems to add ignored files back into the tree. This is mostly a non-issue for me, but take note.
Tuesday, July 22, 2008
Less? More? Vim
When viewing large files, people typically tend to use a pager program such as more or preferably less. Neither of these buffers the entire file into memory, so it's quick to open a large file and scroll around. If you're using more, you should try less. It lets you scroll backwards in the file as well as forwards.
Out of the box, Vim doesn't do so great for really big files. Features like syntax highlighting and undo history can really slow things down on huge buffers; however, there is a plugin that can ease the pain. The LargeFile plugin is available here, and it really does seem to speed up opening and moving around in files larger than a few megs. A word of caution though, if you're dealing with really huge files, a pager program is still the way to go due to the sheer amount of memory required to manipulate those files.
Out of the box, Vim doesn't do so great for really big files. Features like syntax highlighting and undo history can really slow things down on huge buffers; however, there is a plugin that can ease the pain. The LargeFile plugin is available here, and it really does seem to speed up opening and moving around in files larger than a few megs. A word of caution though, if you're dealing with really huge files, a pager program is still the way to go due to the sheer amount of memory required to manipulate those files.
Friday, July 18, 2008
Sorting Files By Size
In case anybody was wondering, I'm still alive. I've been inordinately busy lately and have been spending the majority of my free time online re-learning Ruby on Rails. I've also been digging into multi-master and circular replication schemes for MySQL and MySQL proxy. I plan on sharing some of the things I've learned sometime in the near future. Anyway, here's a handy tip that I just used this morning.
If you want to sort all the files in a directory by size, you can do the following:
ls -lsR | sort -nr
The sort command will order by the number of blocks in each file. The biggest files are at the top.
If you want to sort all the files in a directory by size, you can do the following:
ls -lsR | sort -nr
The sort command will order by the number of blocks in each file. The biggest files are at the top.
Tuesday, May 27, 2008
Running Out of Space?
Running out of space on your HD? I am on a few of my machines. I found the following small Perl script that does a great job helping me locate redundant files. It recurses through a given root directory and looks for files of the same size. When it finds two files of the same size, it does an md5sum on them to determine if they're duplicates. It runs pretty quickly and is easy to tweak to pipe into other scripts.
Find duplicate files.
Find duplicate files.
Subscribe to:
Posts (Atom)