Tag Archives: Linux/Unix

history command in Unix

The history command can be used to determine the log of commands we have typed in the bash shell.

If you want to clear the history of commands, the following option can be used:

history -c

If you want to search for a command in history, we can use the grep command

history | grep cp

The following command will show the last n commands:

history n

cp command in Unix

cp is the copy command in Unix environment.

Example: cp -fRvp source destination

-f = For each existing destination pathname, remove it and create a new file, without prompting for confirmation regardless of its permissions.

-R = If source designates a directory, cp copies the directory and the entire subtree connected at that point.

v = Verbose mode, shows files while they are copied

p = Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, ACL, user ID and group ID, as allowed by permissions.

source = e.g. /Volumes/HDD1/Project2015

destination = e.g. /Volumes/HDD2/Project2015_Backup

The cp utility exits 0 on success, and >0 if an error occurs.