Questions tagged [directory]

A file system structure in which to store computer files.

Filter by
Sorted by
Tagged with
7
votes
3answers
24k views

bunzip2 to a different directory

Say I have a file foo.tbz2 in a directory. I want to extract the tar file from the archive, but to a different directory. It seems like bunzip2 will only extract the archive to the same directory as ...
7
votes
2answers
4k views

Difference between rmdir and rm -r

I usually delete directories by using rm: rm -r myDir However I am aware of another command, rmdir, which seems to do the job just as well: rmdir myDir What is the difference between these two ...
7
votes
5answers
2k views

How to execute a bash command in all possible subdirectories?

Let's say my main directory is /home/test Under it I have lots of subdirectories and under subdirectories still a lots of them and so on. Example: /home/test /home/test/subdir1 /home/test/subdir1/...
7
votes
2answers
18k views

tar compression without directory structure

Under my current directory, I have two sub-directories: dir_1/ - file1.png - file2.png ... - fileN.png dir_2/ - fileA.txt - ... - fileZ.txt When I tar compress the two ...
7
votes
4answers
5k views

How to create a short path?

We have so many useful folders, which are in different path, for our working in Linux. For example : $ cd ~/Documents/Courses/EDX/physics2013/ $ cd ~/Documents/Company/OpenGL/Proj/... $ cd ~/...
7
votes
1answer
8k views

Can we use symbolic link and hard link for directories?

I know we can do that for files. What about directories? It seems that cpanel uses that a lot.
7
votes
2answers
7k views

How do I create a ZIP archive that preserves only the structure of the target directory and below?

I need to create a zip archive where the unzipped result preserves the directory structure from the specified directory down. I also need to do this without actually switching to the directory. My ...
7
votes
3answers
12k views

Symlink all subdirectories in a directory to another directory

I'm trying to symlink every directory in a folder to another folder. For example, in the structure below, I need the subfolders symlinked to folder2. - /home/chris/folder1 -- subfolder1 -- subfolder2 ...
7
votes
1answer
825 views

ls *.csv --ignore=“*pattern*” returns files which contain “pattern”

Why does ls --ignore not ignoring the pattern? Looking at the below example: mkdir books cd books touch books_abby.csv touch books_karen.csv touch books_david.csv touch books_tom.csv This creates ...
7
votes
3answers
8k views

How to go back n levels of directories from the command line?

For example, I do the following cds in succession- cd /tmp cd /home/admin cd /root/ cd /some_other/directory Now I am in /some_other/directory. Now, is there anyway to go back to /tmp, the directory ...
7
votes
1answer
150 views

Why directory with large amounts of entries does not shrink in size after entries are removed?

Close vote notice: While the linked duplicate asks same question, the comments and the only answer do not provide an answer which draws from authoritative source. The answer on my question by Thomas ...
7
votes
6answers
2k views

How to find out whether two directories point to the same location

Do the following paths point to the same disk location? /home/username /app/home/username
7
votes
1answer
471 views

Why ls without -l return 1 when permission to directory is r--

I have read this and this, and found that my problem is different and more specific. I understand the following points. +x on the directory grants access to files inodes through this specific ...
7
votes
2answers
26k views

How to find number of Subdirectories under a given directory [duplicate]

In windows you get a count of the number of subdirectories within a directory.Is there any equivalent on Linux ? I'd like it to count recursively & Not stop at a single level.
7
votes
1answer
346 views

cd and ls behave differently when inside a softlink to a dir

When we cd into a dir via its softlink, i observe: ls .. will show the content of the parent dir of the linked dir, while cd .. will go under the parent dir of the softlink. Why are they different? ...
7
votes
2answers
995 views

Untar subfolders with initial folder's content in linux

I have a directory, /Landsat_Data/ which contains subdirectories (Landsat_Data/Site1, Landsat_Data/Site2, etc.). Each subdirectory contains .tar.gz files (e.g. /Landsat_Data/Site2/LE70930862008092-...
7
votes
1answer
4k views

Recursively compare directory contents by name, ignoring file extensions

I have a directory containing about 7,000 music files. I used lame to recursively re-encode all files in it to a separate directory, outputting all files with the same relative path and file name. ...
7
votes
1answer
5k views

how to make gnome use my home folder as Desktop folder?

Environment: Debian 7, gnome-shell. I dislike having a Desktop folder and a Home folder. I like all the applications to use my home folder. Specifically I am concerned about nautilus and gnome-...
7
votes
2answers
18k views

How to make a Desktop “shortcut” that opens the terminal but under a different directory than the default home?

Objective I am looking for an easy way to consistently run a terminal that automatically opens to a specific directory. Is there a way to do that without changing the default directory? Preferably I ...
7
votes
1answer
923 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 ...
7
votes
1answer
3k 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: ...
7
votes
1answer
10k views

Listing both ls information and mount points of a directory?

On my Ubuntu Natty, typically all new drives inserted (e.g. USB Flash thumbdrives) are mounted under /media. So, on my system, I can do something like this: $ mount | grep '/media' /dev/sda6 on /...
6
votes
6answers
2k views

Creating 50 directories with 50 files inside

I am trying to create 50 directories (dir-01..dir-50). And I want to create 50 files (01.txt..50.txt) inside each of the 50 directories. For example: dir-01/01.txt..50.txt dir-02/02.txt..50....
6
votes
11answers
2k views

Ability to easily switch between directories in different areas [duplicate]

I'm doing something where I'm frequently changing between two directories far away from each other in the system's file tree. Is there anyway I can assign some kind of short name to each one for use ...
6
votes
5answers
14k views

Get the parent directory of a given file [duplicate]

Suppose file stores the pathname of a non-dir file. How can I get its parent directory? why does the following way by appending /.. to its value not work $ cd $file/.. cd: ./Tools/build.bat/..: ...
6
votes
4answers
6k views

Is it possible to make multi-level directory? [duplicate]

Using mkdir() (the C function) I can create a 1-level directory, if I want to create multi_level directory like: folder/subfolder/subsubfolder is it possible? if so, how?
6
votes
4answers
2k 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 name)...
6
votes
6answers
887 views

Checking for the existence of multiple directories

I want to check for the existence of multiple directories, say, dir1, dir2 and dir3, in the working directory. I have the following if [ -d "$PWD/dir1" ] && [ -d "$PWD/dir2" ] && [ -...
6
votes
3answers
4k 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 ...
6
votes
3answers
6k views

How to find a depth of a directory

Is there a way to find a maximum depth of given directory tree? I was thinking about using find with incrementing maxdepth and comparing number of found directories, but maybe there is a simpler way?
6
votes
5answers
809 views

How to delete all directories in a directory older than 2 weeks except the latest one that match a file pattern?

I have the following path: /dir1/dir2/ In this path I have the following directories containing various (not relevant) application detrius: follower1234 1-Dec-2018 follower3456 2-Dec-2018 ...
6
votes
4answers
574 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 ...
6
votes
3answers
2k 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?
6
votes
1answer
7k views

What's the name of the top-level directory

I am using Ubuntu. I know by using cd ~/ , I can go to home/ directory. But if I want to go to the directory (I do not know the official name of this directory) which contains etc/, var/, opt/, ... ...
6
votes
2answers
983 views

* at end of directory path

I have a question about the * character at the end of a directory path in a bash script. I have a script that's supposed to automatically delete some archives from a server once they get old enough. ...
6
votes
2answers
5k views

Is there a way to empty the trash/wastebasket from the command line?

This would be great especially considering the latest version of Ubuntu is very slow when displaying directories on my PC...
6
votes
1answer
8k views

mv file without write permission to the source file

I just realised that I can move a file that I do not own and don't have write permissions on. I have write permissions to the directory, so I am guessing that is why I could move it, but in this ...
6
votes
2answers
383 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
1answer
14k views

How search for a file beginning with either a or z and ending with a or z?

I attempted find -name 'a*' 'z*' '*a' '*z' but it gave me the error code find: paths must precede expression: z* I know how to find files starting with a though z, or ending with a-z, but not ...
6
votes
2answers
3k views

Refer to an item in `dirs`

I use pushd to work with multiple directories in bash and zsh. I've aliased dirs to dirs -v so that I get an ordered list when I want to see what's on the directory stack: chb$ dirs 0 /Volumes/...
6
votes
1answer
315 views

Why can't you move another user's directory when you can move their file?

Following on from another user's question I've bumped into a quirk of Linux filesystem permissions that I can't easily rationalize: sudo mkdir ~/foo ~/foo/bar sudo touch ~/baz mkdir ~/my_dir chown ...
6
votes
1answer
7k views

zip all files and subfolder in directory without parent directory

I have the following folder structure folder | |--foo.txt | |--sub_folder | |--bar.txt I want to zip the content (files and sub folders) of folder without including the root folder in the zip. ...
6
votes
1answer
34k views

Remove soft link but not the target

I have a directory that contains a link to another directory that I just created. I would like to remove the link but preserve the directory my link was pointing to. How do I do this? > mkdir rgac ...
6
votes
8answers
7k views

Run a command on all subfolders

If you have a series of subfolders (like from a to z) and want to run a command on each one of them (like rm *.pdf or ls *.pdf), how do you do that? The "manual" approach would be cd a, rm *.pdf, or ...
6
votes
1answer
5k views

Can't rename a directory that I own

I have a directory with a big load of sub directories. I own all of them, and the permissions are all 777. pascal@azazel /box $ ls -al total 147872 drwxr-xr-x 293 root root 12288 aoû 22 19:44 ....
6
votes
2answers
587 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
2answers
693 views

Why is the size of a directory either 0 or 4096? [duplicate]

$ ls -l total 28 drwxrwxrwx 1 t t 4096 May 8 2018 dir1 drwxrwxrwx 1 t t 0 Mar 12 2015 dir2 drwxrwxrwx 1 t t 4096 Jan 17 2014 dir3 drwxrwxrwx 1 t t 4096 Jun 12 2017 dir4 drwxrwxrwx 1 t t ...
6
votes
1answer
231 views

The number of links for a folder doesn't reflect the real status?

A question for ls command. root@cqcloud script]# ls /var/www/html -la total 36 drwxr-xr-x 9 root root 4096 Aug 31 01:12 . drwxr-xr-x 7 root root 4096 Aug 31 01:10 .. drwxr-xr-x 2 root root 4096 ...
6
votes
2answers
1k views

Preventing the creation of a specific directory

I'd like to cover the bases on a vulnerability which tries to download itself and save the result in a newly created directory inside the /tmp/ directory. To be on the safe side, I wish to make it ...
6
votes
3answers
141 views

Is there an easy way to change directories from within one duplicate folder structure to another?

On our server, we have several duplicate-ish folder structures for testing, staging, and production. Other than minor changes, the folder structure between all three are generally the same. When I'm ...