Tag Info

Hot answers tagged

13

A slightly more portable way to handle temporary files is to use mktemp. It'll create temporary files and return their paths for you. For instance: $ mktemp /tmp/tmp.zVNygt4o7P $ ls /tmp/tmp.zVNygt4o7P /tmp/tmp.zVNygt4o7P You could use it in a script quite easily: tmpfile=$(mktemp) echo "Some temp. data..." > $tmpfile rm $tmpfile Reading the man ...


5

If you're looking for the same thing in fewer lines... for TMPDIR in "$TMPDIR" "$TMP" /var/tmp /tmp do test -d "$TMPDIR" && break done You could write this in one.


3

By default, find includes everything in its search: directories, files, and symlinks. find "/path/to/dir" -mmin -30 -not -name ".*" -exec zip -r "testfile.zip" "{}" \+ If /path/to/dir was modified in the last 30 minutes, it will pass all the tests, and zip, since it was given the -r option, will add the directory and everything under it to the archive. ...


2

Read permissions on a directory only allow you to list its contents. To actually be able to access the contents, you need execute permissions. Conversely, having only execute permissions will allow you to access the contents, but not list them. See Why do directories need the executable (X) permission to be opened?


2

Change your aliases to variable like below without cd command and without space after = sign and remove last / because the aliases won't work inside cp command or you can use function instead; As @jherran's answer which it's more flexible with function. sorc=~/e_empid dest=~/e_empoid/dir1/dir2/dir3/Backupfile1 Then use that like: cp $sorc/file1 $dest/ ...


2

if lastdir is the only directory of that name in your directory hierarchy, you might get away with this in bash (although it may take a while to run) shopt -s globstar cd **/lastdir


1

I expect that the files have more space allocated on disk than they are actually using. Normally I'd expect to see this only in binary files where blocks of NULLs are not stored. Since fastq format is text however I think the file allocation extends past the end of the data. Try the command ls -lsh and compare the two sizes listed for each file. Column 1 is ...


1

I do not think it would make much sense to implement such functionality in 'cd'.. It would work if every subdir had only one sub-subdir, but what if there's a tree [i.e. several subdirs in a dir]? Which path should it take? 'cd' is not a mind reader. Consider the following two direcroty trees: <some_parent_dir> | |-<subdir> | | | ...


1

Directories have two ways of operation. The first is to read or browse a directory, also known as running the ls command, and the other is executing a directory. Executing is required to open a file or directory in the requested directory. Executing is doing an inode lookup for the requested name and you don't have to be able to read the directory for that. ...


1

Instead of cp -r usr/* /usr, do: cp -ri usr/* /usr The -i flag will make the copy process interactive and will ask your permission if it will overwrite any files. You will have an option either to grant or not to grant the permission. P.S:- The version of cp on my test server is 8.4. It does not ask for permission before over-writing files unless I use cp ...


1

mv /images/images/ .. moves the directory called images from the directory /images into the parent directory of the current directory. The current directory is whichever directory you were in at the time you ran the mv command. Your directory will not have "disappeared". You just need to work out where you were when you ran the mv command, and from there ...


1

.. denotes the parent directory. Suppose you are in the home/user/TEST folder, where there is the images1/images2 directory. Then you have now a images2 folder in home/user/ and an images1 folder in TEST, without the subdirectory images2: ~$ mkdir TEST ~$ cd TEST ~/TEST$ mkdir -p images1/images2 ~/TEST$ touch images1/images2/a_file ~/TEST$ mv ...


1

If you are using bash, you can create a function instead of an alias. bcopy () { cd ~/e_empid/ cp file1 /home/e_empid/dir1/dir2/dir3/Backupfile1 cd ~/e_empoid/dir1/dir2/dir3/ } Then you just need to call using bcopy. You could also use $1 and $2 instead of file1 and Backupfile1 if your files does not have the same names every time. cp $1 ...


1

I am not aware of a possibility to lock the file system meta data in the cache but (if there are not too many files) you can read the meta data regularly in order to keep it in the cache: find /path/to/dir -printf ""


1

You can use the -l option of the cp command, which creates hard links of files on the same filesystem instead of full-data copies. The following command copies the folder source/folder to a parent folder (destination) which already contains a directory with the name folder. cp -rl source/folder destination rm -r source/folder You may also want to use the ...


1

If rsync is not an option, I would next recommend lftp: lftp sftp://user@host.com/path/path/ Then use the mirror command to recursively upload, like this: mirror -R Or to upload just: mirror You have to cd into the directories you want to mirror. Works great!



Only top voted, non community-wiki answers of a minimum length are eligible