File and Directory Operations

Print current working directory:

Show files in current directory:

Show maximum information about all files, including hidden:
ls -a

Recurse into subdirectories and list those as well:
ls -R

List files by modification time, most recent first.
ls -lt

Move/rename a file or directory (be careful that you don’t move the source over a destination with the same name):
mv sourcename destinationname

Bulk file rename
$ rename s/”SEARCH”/”REPLACE”/ *

  • This will replace the string SEARCH with REPLACE in every file (that is, *). If you want case insensitive, add /i. Note:the -n option will just show what would be renamed, then exit. This is useful, because you can make sure you have your command right before messing all your filenames up.

Delete target forever (be very careful the target is not sent to trash it’s gone), use -r recursive flag for directories:
rm target

# Copy file or directory:
cp sourcename destinationname

Mount filesytem:
mount /dev/device_name /media/device_name

Unmount filesystem:
umount /media/device_name

Remount your entire filesystem:
sudo mount -a

Work with disk partitions:

Filesystem creation tool:

Create a symbolic link to /targetdirectory/targetname in directory linkdirectory called /linkdirectory/linkname
ln -s /targetdirectory/targetname /linkdirectory/linkname

note if you are not the owner of these directories you will need to use:
sudo ln -s /targetdirectory/targetname /linkdirectory/linkname

Print a file in terminal:
cat file

View the output of a command in a more convenient format:
command | less

Find files matching filename:
locate filename

See the version of a program or the location of the program
which appname

Search through filename for matches to phrase:
grep phrase filename

View what processes are using what files:

View files in directory from largest to smallest:
du -a directory | sort -n -r | less

Remove spaces from filenames in current directory:
rename -n ‘s/[\s]/”/g’ *

# change capitals to lowercase in filenames in current directory:
rename ‘y/A-Z/a-z/’ *

View the differences between two files:
diff file_1 file_2

Output the top number_of_lines of file:
head -n number_of_lines file

Like head, but it outputs the last -n lines:
tail -n number_of_lines file

Checksum a file:
md5sum file

Checksum every file in a directory (install this one from repositories.):
md5deep directory

Checksum a file (better algorithm with no hash collisions):

Same operation as md5deep, but using sha1:

  1. Good research and explaination done on Ubuntu. Worked for me

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: