Tag Info

Hot answers tagged

18

~ is a special name expanded by the shell, . and .. are real proper directory names, so no expansion is done by the shell there.


12

One way to delete files/direcories like this is by their inode-reference. To find the inodes for elements in current dir: ls -i 14813568 mikeaâcnt To delete this: find . -inum 14813568 -delete


11

You've misinterpreted the primary rationale for "hidden files". It is not to prevent users from messing around with things. Although it may have this consequence for very new users until they learn what a "dot file" is (dot file and dot directory are perhaps more appropriate and specific terms than "hidden"). All by itself it doesn't prevent you from ...


10

Using rsync can accomplish this. Based on the type of system you have, you will need to donwload it: sudo yum install rsync (RPM Based) sudo apt-get install rsync (Debian Based) Then using this, here is the command you will need to use: rsync -a source destination Or rsync -r source destination Where -r stands for copying data recursively (but don’t ...


8

The following excerpt from this essay potentially explains why that directory refuses to be deleted: NFSv4 requires that all filenames be exchanged using UTF-8 over the wire. The NFSv4 specification, RFC 3530, says that filenames should be UTF-8 encoded in section 1.4.3: “In a slight departure, file and directory names are encoded with UTF-8 to deal with ...


7

You should not use non-ASCII characters in the command line since as you could see, for some reason, they won't necessarily correspond to the filename (Unicode has various ways for expressing accented letters). Something like: rm -rf mike* should work since the filename is directly generated by the shell. But make sure there's only one match (do an echo ...


7

use rsync: rsync -a --ignore-existing cosmo_sim_9 /dest/disk/cosmo_sim_9 --ignore-existing will cause it to skip existing files on the destination, -a will make it recursive, preserving if possible permission/ownership/group/timestamp/links/special devices. you can do it for all directories by using a bash for loop: for dir in cosmo_sim_* ; do rsync -a ...


6

Directories are special in the sense that within a directory you can have references to several files and directories, so, if you remove the parent directory, all those files lose their reference point from where they can be accessed, the same with process. For such cases, rmdir() have different checks, that are different from unlink(): If the directory is ...


5

. is not a bash (or any other shell) built-in. Each and every directory has entries . and .. in it. You can verify by cd'ing to some arbitrary directory and doing ls -lia . You will see . and .. entries. I had you use the '-i' flag on ls to get inode numbers: note them for . and ... Go up a directory, but doing cd .. or cd /something/soemthingelse/whatever. ...


4

You could use something like find . -maxdepth 1 \( ! -type d \) -exec sh -c 'mv "$@" MYDIR' _ {} \; First we use find to look only within the current directoy, then we ignore directories by using ! -type d finally we execute sh and move everything to the destination dir. You might try {} + at the end which will be faster.


4

It did that because . isn't a name that can be used to create a subdirectory. cp -a . ~/xyz copies ./file1 to ~/xyz/./file1, ./file2 to ~/xyz/./file2, etc. But ~/xyz/./file1 and ~/xyz/file1 are the same, so the effect is to copy the contents of the current directory to ~/xyz. You can see this if you add the --verbose option to cp to display each pathname ...


3

I guess its pretty clear from the Man pages. And by the way what is your question? What part of the man page is not clear to you? With the execute bit set you have the permission to cd into the directory Also for long listing ls -l i.e. to view the meta data of the files inside the directory (Provided that read permission is there for the directory.


3

pwd will print the value of $PWD if it contains an absolute pathname that does not have dot . or dot-dot ... From POSIX pwd definition: -L If the PWD environment variable contains an absolute pathname of the current directory that does not contain the filenames dot or dot-dot, pwd shall write this pathname to standard output. Otherwise, if the ...


3

Assuming you're using Bash which has pwd as a builtin1, what happens is that the cd command triggers the shell to update the information regarding the current directory. Until you run cd, the shell will think that the current directory hasn't changed, so it doesn't try to get its new path. By the way, to expand a bit on Gnouc's answer, the Open Group Base ...


3

Probably not, though this may have surprised the devs as well. Here's a comment from an excerpted GNU's ls.c: # /* Extensions only apply to regular files, apparently. */ Here is a link to the full ls.c source in which you will find the same, though it is not as pretty to read, maybe. It is worth noting though you can get some alternation in color for ...


3

The answers given until now do not take into account that the file list passed from find to du may be so long that find automatically splits the list into chunks, resulting in multiple occurences of total. You can either grep total (locale!) and sum up manually, or use a different command. AFAIK there are only two ways to get a grand total (in kilobytes) of ...


3

An easy way is to just create a directory in /tmp and use a symlink: mkdir /tmp/mine ln -s /tmp/mine /home/me/tmp You may want to chmod 700 /tmp/mine to keep it private. If you instead want to mount an actual separate tmpfs directory: mount -t tmpfs -o size=100M tmpfs /home/me/tmp You need root privileges to do this, but normal permissions rules apply ...


3

I have personally tested using find's -exec directive: $ mkdir -p mikeaâcnt $ ls mikeaâcnt $ find -maxdepth 1 -type d -empty -exec rm -rf {} + $ ls $ The folder was correctly created and correctly removed. As pointed out by @Igeorget, there's an even simpler method if you have GNU find: $ find -maxdepth 1 -type d -empty -delete I also tested this ...


2

Regex aren't involved here. Wildcards in bash (like most other shells) only match files based on the file names, not based on the file type or other characteristics. There is one way to match by type: adding / at the end of the pattern makes it only match directories or symbolic links to directories. This way, you can move directories, then move what's left, ...


2

The only safe way is to Copy all the files to a different filesystem. Unmount the filesystem. Wipe the partition or volume containing the filesystem. This is the “hard-drive blaster” you mention in your question. Don't use dd, cat is just as good. You can do that remotely, unless this is the root filesystem, in which case what you want to do is impossible. ...


2

So you want to hide directory names... an experiment. # truncate -s 1G foobar # losetup -f --show foobar /dev/loop0 # mkfs.ext4 /dev/loop0 # mount /dev/loop0 /mnt/tmp # cd /mnt/tmp # mkdir collywobbles # sync # mv collywobbles shriggelfigs # sync # mv shriggelfigs flapjacks # sync # rmdir flapjacks # cd .. # umount /mnt/tmp So basically we have an empty ...


2

/etc/skel contains files to be copied to new user's home directories, therefore the names are, of course, the same as in an user's home directory. This explains /etc/skel/.bash_profile. The directory /root also is a home directory, namely the home directory of the user root. This explains /root/.ssh and /root/.config. /etc/.pwd.lock seems to be a lock file. ...


2

This might be a highly opiniated answer, but I think the main reason dot files and dot directories are marked like that is not to hide or obscure them - I think it's just to let the user know that within those files and directories are program's and user's settings that can be changed by them or by the programs themselves. The fact that dot files and dot ...


2

@Praveen J Kumar , I'm not so clear, so I'll try to cover the basics. There are four cases here: You do want to get prompt when deleting a directory. -i flag is for interactive session, and will ask you before each file is deleted. -r is for recursive, i.e. go over the entire directory and sub directories etc.... Then use: $ rm -ri <directory path> ...


2

These are backup files that gedit creates by default. You can disable this feature by going to Preferences → Editor and unchecking the line Create a backup copy of files before saving


1

This is a job for rsync. There's no benefit to doing this manually with a shell loop unless you want to move the file rather than copy them. rsync -a /images/ /images2/ If images with the same name exist in both directories, the command above will overwrite /images2/SOMEPATH/SOMEFILE with /images/SOMEPATH/SOMEFILE. If you want to replace only older files, ...


1

@inulinux12 , you can use the following one line for loop from command line: $ for dir in images2/*; do mv "$dir"/* "${dir/2/}"; done This will move all of the files from images2 to images in their respective directories. Note: this assumes no files have the same name. For example: Before execution: $ ls -R images* images: ad adfoo fe images/ad: ...


1

The rmdir does not provide an -i flag like rm command does when you want to confirm a deletion of a certain directory. However, rmdir returns an exit code of 0 when it operates on an empty directory. For example: $ mkdir emptydir && rmdir emptydir && echo $? 0 As you can see, it does not ask us for confirmation when deleting an empty ...


1

Look at the manual for cp (also mv): cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... If you do cp a b then if b does not exist you get cp -T a b, but if b exists and is a directory you get cp -t b a, else error. Example mkdir empty cd empty mkdir a touch a/a-file cp -r a b #this creates ...


1

Just do as you did: cp -r dir1 dir2 and you will have dir1 (with its content as well) inside dir2. Try if you don't believe ;-). The command that would copy content of dir1 into dir2 is: cp -r dir1/* dir2



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