Tagged Questions
1
vote
2answers
63 views
cat files in current folder and all subfolders [duplicate]
I want to cat a file in current folder and all files in all subfolders (and subsubfolders).
Here is my directory structure
$ tree
.
├── f
│ └── foo
└── yo
I want to cat foo and yo.
I've tried ...
1
vote
8answers
110 views
remove content of directory in elegant way
I would like to remove all content of the current working directory.
How to do it in efficient and elegant way?
I have several files, directories and some of them starts with dot, like:
touch .abc; ...
1
vote
2answers
52 views
How to strip directory structure with command line (or script)
I have a large collection of files packed into a two-level directory structure with many, many, many folders.
In other words, I have a folder with a great many subfolders in it. There are no ...
5
votes
3answers
259 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 ...
2
votes
4answers
125 views
Find directories that do not contain subdirectories
I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories.
I know that I could use ls -alR and recursively parse ...
3
votes
1answer
69 views
Passing all files of specific filetype in current and subdirectories
I have constructed an elaborate 500+ character command with many arguments and switches to autosign multiple PDF documents.
I'm using JSignPDF and I'd like to use it's batch mode including the ...
3
votes
4answers
112 views
mkdir -p for files
mkdir -p will create a directory; it will also make parent directories as needed.
Does a similar command exist for files, that will create a file and parent directories as needed?
7
votes
1answer
144 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 ...
1
vote
1answer
106 views
What is the “~/” directory?
I'm trying to locate where some files are stored and I can easily browse to them via ssh by going to "cd ~/foldername", however, I have no idea what directory "~/" actually is.
When I browse around ...
0
votes
1answer
70 views
Create a File with Touch on a specific Directory
I want a create a file with a specific extension(.done). I am using the command touch. Something Like:
touch `basename $UNZIPFILE`".done"
It's creating the file but in current directory. I want to ...
1
vote
3answers
168 views
I want to run commands like make, make install, python setup install without changing directories
I have written a script which will download software from the internet to the current user's home directory and then untar it. And then I have to make and make install it and in some software I have ...
4
votes
2answers
222 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 ...
1
vote
3answers
97 views
Restructuring directories into a hierarchy
I have the following type of folder structure containing thousands of folders.
The folder names are as such with different names etc
.test
.test.subfolder
.test.subfolder.subsubfolder
.folder
...
0
votes
2answers
813 views
How to change the working directory of invoking shell using a script? [duplicate]
Possible Duplicate:
changing current working dir with a script
I am trying to create few scripts that would change the working directory of the main shell/terminal. Not able to do so. I ...
1
vote
5answers
1k views
ls: Do not show directories that match same pattern in wildcard searches, only files
Supposing I have something like the following, a typical business PC situation:
drwxr-xr-x 1 whatever whoever 3 Oct 3 16:40 invoices2009
drwxr-xr-x 1 whatever whoever 4 Oct 3 16:40 ...
1
vote
2answers
282 views
Create and move to a directory in one command - unix [duplicate]
Possible Duplicate:
Is there a one-liner that allows me to create a directory and move into it at the same time?
I know this is a very basic question but I can't seem to figure out what to ...
9
votes
5answers
1k views
Creating numerous directories using mkdir
I would like to create many directories using mkdir. Each directory name will consist of a prefix (a string) and an index (an integer). Suppose that I would like the prefix to be "s" and the indices ...
7
votes
3answers
275 views
How to remove only the content of directories?
I'm in a folder: /var/myfolder.
Inside there are some other folders like: /var/myfolder/A/ /var/myfolder/B/ `/var/myfolder/C/ etc.
Inside each there are some files with random names. How do I ...
3
votes
2answers
157 views
open a file using CDPATH and symlink
To quickly move around, I added a path to CDPATH that contains symlinks to different locations. I did this by adding the following line to .bashrc:
export CDPATH=~/symlinks
When working with ...
1
vote
1answer
1k views
How do I remove a directory and all its subdirectories?
I'm trying to learn some directory navigagtion with bash and all I know is that
rmdir directoryname
will remove the directory but not if it's containing something. Is there a way to force it to ...
4
votes
1answer
148 views
xterm doesn't switch directory when it is moved
Recently I was very frustrated with xterm not behaving as expected. This is what I was doing:
open xterm
run the following commands:
$ mkdir test_01
$ cd test_01/
$ echo 'a' > a
$ cat a
The ...
2
votes
4answers
523 views
Make directory copies using find
I have a directory with a bunch of subdirectories in it. Thus
/usr/local/src/ccl/ccl-1.8/x86-headers$ ls
elf gl gmp gnome2 gtk2 jni libc
Each of these directories has a further subdirectory C ...
2
votes
3answers
2k views
How can I delete all files with a particular extension in a particular folder?
If I set the current/working directory (navigating to it using cd) to some particular directory and then type:
rm *.xvg
What will this command do? Is it true that the above command will only delete ...
7
votes
2answers
393 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 ...
3
votes
1answer
434 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 ...
3
votes
1answer
300 views
creating abbreviations for commonly used paths
I am new to linux and was wondering whether it is possible to create abbreviations that can be used in terminal. I know about alias command, but am not sure whether that can be used for what I am ...
9
votes
4answers
644 views
Best method to collect a random sample from a collection of files
Suppose there is a directory holding 300 data files. I want to randomly select 200 of those files and move them into another directory. Is there a way to do that under Unix/Linux?
5
votes
4answers
892 views
Recursively rename subdirectories that match a regex
I have a media server with a folder called Series. (/media/Expansion2/Series/)
In it, I have (surprise!) TV series. These are just the show names, e.g., /media/Expansion2/Series/The Big Bang Theory/
...
30
votes
3answers
933 views
How can I cd to a directory just by typing the directory's name?
I either had this somewhere 20 years ago or I dreamed about it.
Basically:
If if type blobblob I get
blobblob: command not found
Fair enough.
I would like it so that when my shell gets those ...
9
votes
4answers
2k views
symbolic link to a directory and relative path
I've created symlink with absolute path to the directory (Blink) and have for example following tree:
$ ls -l /tmp/A
total 0
lrwxrwxrwx 1 root root 6 Apr 3 12:27 Blink -> /tmp/B
-rw-r--r-- 1 root ...
4
votes
1answer
128 views
What is the tool that allows me to specify arbitrary directories using **
I once saw a colleague uses a tool which allows to use ** to represent any directories. For example: if a file called myfile.java sits deep inside:
src/main/com/mycompany/product/store/myfile.java
...
3
votes
3answers
1k views
process files in a directory as they appear [duplicate]
Possible Duplicate:
How to run a command when a directory's contents are updated?
I'm trying to write a simple etl process that would look for files in a directory each minute, and if ...
3
votes
2answers
122 views
How do I create a structured list of all the files and directories under a particular directory (recursively)?
I need to have an "image" of a file system without actual contents of the files - just all the names and the structure, so that I can read the file and know what files were stored there and how were ...
7
votes
6answers
4k 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 ...
1
vote
3answers
442 views
shell commands to check & create dir
I am writing a Ruby script inside which I would like to invoke/execute some shell commands.
The shell commands I would like to run should check if a directory named 'tmp' under /var/lib/mysql/ exists ...
11
votes
5answers
7k views
Script to monitor folder for new files?
How do I detect new files in a folder with a bash script? I would like to process the files as soon as they are created in the folder. Is this possible to do so or do I have to schedule a script with ...
11
votes
4answers
4k views
Converting relative path to absolute path
Is there a *nix command to get absolute(and canonicalized) path from relative path(with current path) or symbolic link?
5
votes
6answers
440 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 ...
27
votes
2answers
885 views
Why is '.' a hard link in Unix?
I've seen many explanations for why the link count for an empty directory in Unix based OSes is 2 instead of 1. They all say that it's because of the '.' directory, which every directory has pointing ...
5
votes
3answers
303 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 ...
4
votes
3answers
220 views
mkdir based on input from other directories
I have a directory full of albums I've ripped to FLAC format. Folders are named "Artist - Album [flac]" I need to create matching directories named "Artist - Album [mp3]" but only for certain ...
5
votes
3answers
264 views
“mkdir foo; svn mv * foo”
I often want to do some variant of this idiom:
$ mkdir 2010
$ svn mv * 2010
Of course, I get an error because the glob matches 2010 as well:
svn: Cannot copy path '2010' into its own child ...
1
vote
1answer
292 views
Execute file in its native directory with shell script
I'm executing a php file from the php-cli with a shell script. One of the php files creates a file named available_data during the course of its execution. The problem is that the php file needs to ...
2
votes
4answers
2k views
programmatically creating a remote directory using ssh
Using a shell script, how can I create a directory remotely from serverA -> serverB using ssh? Can I pass the create directory command with the ssh command? How?
I'm basically looking to create a ...
6
votes
7answers
2k 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.
13
votes
6answers
1k views
Any way to sync directory structure when the files are already on both sides?
I have two drives with the same files, but the directory structure is totally different.
Is there any way to 'move' all the files on the destination side so that they match the structure of the ...
3
votes
2answers
781 views
How do I delete all files with a given name in all subdirectories?
I want to delete all files with a given name in all the subdirectories of my home directory.
I tried:
rm -r file
in my home directory, but it didn't work because that file doesn't exist in that ...
4
votes
1answer
661 views
how to view a directory's permission
What is the command with which you can directly view the permission bits of a directory?
1
vote
3answers
195 views
Directory filenames with sed with whitespaces
I'm working on a script and I'm stuck, even with the help of teh googles.
Here's my code:
for FOLDER in `find . -type d | sed "s#^.#$(pwd)#" | sed 's/ /\ /g'`
do
echo "$FOLDER"
done
This will ...