A file system structure in which to store computer files.

learn more… | top users | synonyms

9
votes
3answers
352 views

How to spoof/mock a directory used by a binary application as another directory?

Suppose there's a binary application that always writes its data to /tmp. How could I spoof/mock /tmp for the sake of this binary as some other directory (e.g. home/tmp)? Let's assume I have no ...
9
votes
3answers
5k views

Simplest way to password protect a directory and its contents without having to create new files?

I would like to password protect or encrypt a directory and all the files within it (for the whole directory tree below it). I do not want to bother the whole home directory, I want a specific ...
9
votes
3answers
930 views

Lowercasing all directories under a directory

I want to lowercase every directories' name under a directory. With which commands can I do that?
8
votes
7answers
5k views

How do I create a directory in all subdirectories?

Suppose I have a directory structure like this: $ [~/practice] ls a/ b/ c/ d/ Now I want to create a directory tmp1 in all sub directories of practice and I do this: $ [~/practice] mkdir */tmp1 ...
8
votes
5answers
2k views

Bash CD up until in certain folder

I do a lot of work in Magento, and so do a lot of the people I work with, and it gets annoying to have to type: cd ../../../../../../ To only find you're still a few directories from your root ...
8
votes
6answers
27k views

How to remove all the files in a directory?

I am trying to remove all files and subdirectories in a directory. I used rm -r to remove all files, but I want to remove all files and subdirectories, excluding the top directory itself. For ...
8
votes
4answers
3k views

How are directories implemented in Unix filesystems?

My question is how directories are implemented? I can believe a data structure like a variable e.g. table, array or similar. Since UNIX is Open Source I can look in the source what the program does ...
8
votes
6answers
749 views

Best way run a command on each file in a directory tree

There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?
8
votes
3answers
392 views

What are ./ and ../ directories?

Simple question, but I'm not sure where to look and google doesn't respond to periods and slashes. I'm just trying to count the # of files & directories in the current directory (not including ...
8
votes
3answers
966 views

How can I cd to the previous/next sibling directory?

I often have a project directory layout like this project `-- component-a | `-- files... `-- component-b | `-- files... `-- component-c `-- files... I'll usually be working in one of the ...
8
votes
3answers
8k views

How can I move files by type recursively from a directory and its sub-directories to another directory?

What would be a good way to move a file type from a directory and all of its sub-directories? Like "move all *.ogg in /thisdir recursively to /somedir". I tried a couple of things; my best effort was ...
8
votes
2answers
814 views

the slash (/) after a directory name on shell commands

I have a little question here. If I have two files, say filea and fileb, mv filea fileb would delete fileb rename filea to fileb Then if I have two directories, say dira and dirb, mv dira dirb ...
8
votes
1answer
981 views

Can rm recursively remove empty directories?

In an old version of Unix, the rm command would delete directories if they were empty. From the Research Unix Eighth Edition man page for rm: "If an entry is a directory it is removed only if empty." ...
7
votes
6answers
897 views

Is it possible to remove folder prefix from a `ls` command

I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output: lib/mylib_1.jar lib/mylib_2.jar ... Is there any ...
7
votes
6answers
6k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
7
votes
7answers
5k views

How to check if $PWD is a subdirectory of a given path

E.g. check if $PWD is a subdirectory of /home. In other words I'm searching for a bash string operation to check if one string starts with another.
7
votes
4answers
22k views

How can I list subdirectories recursively?

The obvious ls -dR does not work. I am currently using find /path/ -type d -ls but the output is not what I need (plain listing of sub-folders) Is there a way out?
7
votes
3answers
1k views

How to run a command when a directory's contents are updated?

There is a directory A whose contents are changed frequently by other people. I have made a personal directory B where I keep all the files that have ever been in A. Currently I just occasionally ...
7
votes
1answer
3k views

Why can't I have a folder and a file with the same name?

I've never had this problem before, but for some reason, I can't rename my folder to packages/. This is the structure: root - packages_old/ - packages When I try to rename the folder with ...
7
votes
2answers
939 views

Is there a correct way to list the subdirectories of the current directory?

I can find the subdirectories of a directory by ls -d -- */ or ls -l | grep "^d" but both of these seem indirect, and I would imagine that there would be a standard way to find just the ...
7
votes
4answers
3k views

How does one atomically change a symlink to a directory in busybox?

I am trying to (as close as possibly) atomically change a symlink. I've tried: ln -sf other_dir existing_symlink That just put the new symlink in the directory that existing_symlink pointed to. ln ...
7
votes
3answers
6k views

How do I change folder timestamps recursively to the newest file?

I was wondering if anyone knows how to change the timestamps of folders recursively based on the latest timestamp found of the files in that folder. So for example: ...
7
votes
4answers
14k views

Using sftp to Transfer a Directory?

When I try to use sftp to transfer a directory containing files, I get an error message: skipping non-regular file directory_name The directory contains a couple of files and two subdirectories. ...
7
votes
4answers
2k views

Find files with same name but different content?

I want to generate a list of files that have: Same name Different content in a directory (including all children directories and content). How to do? Bash, perl, anything is fine. So, two ...
7
votes
2answers
2k views

Stay at same working directory when changing to sudo

When working on the command line, I often change to sudo using sudo -i. However, my working directory changes automatically to /root. I never want to go there; I want to stay where I was! How can I ...
7
votes
1answer
347 views

What is the significance of the dot in bash commands and how is it different from an asterisk?

I'm trying to understand the significance of the dot in bash and how it differs from an asterisk. Can someone please elaborate? For example, what's the difference between cp -ar /foo/. /foo2/ and cp ...
7
votes
1answer
102 views

Why are rmdir and unlink two separate system calls?

Here's something that kept me wondering for a while: [15:40:50][/tmp]$ mkdir a [15:40:52][/tmp]$ strace rmdir a execve("/usr/bin/rmdir", ["rmdir", "a"], [/* 78 vars */]) = 0 brk(0) ...
7
votes
1answer
218 views

Boot into a chroot?

I have Linux (Debian Jessie) installed on a hard drive. Drive - sda1, ext4fs, and sda2 - swap I have a /chroot folder. There is installed another system, in /chroot folder. Question: How to tell ...
7
votes
4answers
5k views

How can I force unzip / zip not to create a subdirectory when I extract it?

Depending on how a zip file is created, sometimes it will extract all of the files directly, and sometimes it will extract the files into a subdirectory. If the latter is true, how can I force the ...
6
votes
1answer
349 views

Expand ~, . and `..`

Since ~, . and .. are special directories, why are they handled differently in the following example? $ echo ~ /home/tim $ echo .. .. $ echo . . ~ is expanded into the dir, but the other two are ...
6
votes
3answers
3k views

How do I remove all sub-directories from within a directory?

This question is kind of a phase II to the first question I posted at here I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a ...
6
votes
3answers
867 views

Merging folders with mv?

If I move a folder with mv called "folder" to a directory that already contains "folder" will they merge or will it be replaced?
6
votes
5answers
676 views

Making a directory protected from 'rm -rf'

I just lost some data in folder A which was inside folder B after doing rm -rf B. Before I could realize what have I done, it was all over. Now a lesson is learnt, I wish to make some of my folder ...
6
votes
1answer
2k views

how to view a directory's permission

What is the command with which you can directly view the permission bits of a directory?
6
votes
4answers
435 views

set read and write permissions to folder and all its parent directories

I need to set read and write permissions for root user to directory subfolderN and all its parent folders till root. I can do it by hands: $ sudo chmod +rx /root/subfolder1/subfolder2/subfolderN $ ...
6
votes
2answers
220 views

How does one create a directory that can't be seen and can only be accessed via its absolute path name?

I'm working on an assignment on adding time support to a standard UNIX system. Part of it, however, involves securing the location of backup files (which we've set to be at the system root by default) ...
6
votes
6answers
1k views

Remove empty directory trees (removing as many directories as possible but no files)

Suppose I have a dir tree like this: ROOTDIR └--SUBDIR1 └----SUBDIR2 └----SUBDIR3 I am looking for a command such that when I input: $ [unknown command] ROOTDIR The whole ...
6
votes
2answers
314 views

Using NIS without NFS

I'm configuring several computers in a lab to operate with the same login credentials shared between the computers, but without sharing the home directories. I'm considering using NIS for sharing the ...
6
votes
3answers
781 views

Read a directory to see the file to inode mapping

I'm just learning about filesystems and it is said that a directory is just an ordinary file which keeps a list of file-inode pairs. If I try to open the directory Downloads with any of the following ...
6
votes
1answer
621 views

Why could the size of the “dot” file “.” exceed 4096?

Today I found an "empty" directory with a size of 4MB. It had no visible contents, so I tried ls -lah. This showed me some hidden files (not very large). Searching for the reason why the directory ...
6
votes
4answers
2k views

How to recursively find the amount stored in directory?

I know you are able to see the byte size of a file when you do a long listing with ll or ls -l. But I want to know how much storage is in a directory including the files within that directory and the ...
6
votes
1answer
729 views

Is there a tool that hooks to two directories and synchronizes them as soon as something changes?

I have huge simulation directories on the two machines server and on cluster which I want to keep synchronized. The basic situation is that files rarely change but when a simulation is done many big ...
6
votes
1answer
75 views

Expected behavior of `find -depth` if execute permission denied for subdirectory?

I'd like to know if I can rely on the behavior I am seeing when using find with -depth option and user does not have execute permission for a subdirectory. Assume the following directory structure: ...
6
votes
1answer
82 views

Folder with ONLY write permission is useless… right?

Having worked with Linux for years, and finding myself with some free time, I decided to revisit some basics. So I re-read the stuff about permissions (without checking source code), and its special ...
6
votes
0answers
98 views

What's the size of a folder entry? [duplicate]

Possible Duplicate: What does size of a directory mean in output of 'ls -l' command? user@~ > ll /tmp/foo drwxr-xr-x 2 user user 4,0K 1 oct. 15:15 bar What are those 4,0K ? ...
5
votes
4answers
474 views

Equivalent of forward/back buttons for unix shell (when navigating directories)?

I'd like to be able to type in terminal commands of forward/back especially if I went from a directory with a super-long name to home (and want to return back to the directory with the super-long ...
5
votes
3answers
2k views

On deep-created directories

In Windows, there is a certain limit on the number of characters in a path, which restricts how deep a directory can be created. I was wondering what the case is like in Linux? Do you have some ...
5
votes
4answers
237 views

Ways to organize and access frequently visited directories and files?

In my Ubuntu, I have added some frequented directories to the bookmarks of Nautilus, for visiting them quicker. Nautilus can consume a lot of memory, when it has been kept open for long and there ...
5
votes
3answers
582 views

Walking through files in directory randomly

How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
5
votes
5answers
7k views

Find the total size of certain files within a directory branch

Assume there's an image storage directory, say, ./photos/john_doe, within which there are multiple subdirectories, where many certain files reside (say, *.jpg). How can I calculate a summary size of ...