All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1
votes
1answer
58 views

How to copy files one by one to different folders?

In a directory I have files with the names: 01.txt 02.txt 03.txt In the same directory are folders with the names: 01.abc 02.def 03.ghi I need a command to copy the files to the folders one by one,...
1
vote
1answer
38 views

How to reference a child directory, that is part of cwd's path?

Is there a generic way to reference a path that is nested an arbitrary level deep along the cwd? This is almost like a reverse relative path lookup. For example: $ pwd /Users/somebody/foo/bar/baz $...
6
votes
6answers
854 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" ] && [ -...
0
votes
0answers
55 views

Shell script - directory size

I have to create a script that calculates the size of a directory given as an argument in bytes, like ./du.sh dir. Optionally I have 2 other arguments: ./du.sh dir 1000 files.txt, where 1000 stands ...
3
votes
1answer
2k views

Recursive shell script to list files

I'm trying to write a shell script that lists certain types of files in a Directory (and sub-directories). I'm struggling with the recursive part. Here's what I have: #!/bin/sh #download dir ...
1
vote
2answers
38 views

Calling dir names from a paramater list file

Wondering if there is a best way to call directory names and iterate as parameter from a list. Example cat /dropbox/script/DirList.txt DIR_A DIR_B DIR_C DIR_D /dropbox/dev/inbox/<DIR_A>/ *.*...
0
votes
0answers
38 views

Complex nested for loop in directory

I have two sets of files in two separate directories organized as such: #first directory /direc1/files file0.num1.tar.gz file0.num2.tar.gz file0.num3.tar.gz file0.num4.tar.gz . . . ...
1
vote
2answers
112 views

find: exclude n different directories and m different files present at any level but include few files from some excluded directories

I want to recursively find all directories and files inside a path but want to exclude some other directories and files that match given patterns. I then want to execute further commands on the search ...
0
votes
1answer
46 views

Meaning of dot (.) in The Following Examples

I would like to know the meaning of the dot (.) in the following examples: dotslash at the front of the path: cp -r ./dist/amd/ ../../aurelia-amd/animator-css Is this equivalent to cp -r dist/amd/ ...
0
votes
2answers
38 views

Delete directories if they do not have newer files

I want to delete directories only if they have not changed in the last N days. And by changed I mean contain any files that are more recent than N. I constructed something similar / found this but ...
-1
votes
1answer
1k views

Find files in specific directories

I have a college exercise which is "Find all files which name ends in ".xls" of a directory and sub-directories that have the word "SCHEDULE", without using pipes and using only some of the commands ...
0
votes
2answers
39 views

Shell script to move empty folders into a subfolder

I have many empty folders that I do not want to delete but move to a subfolder called "my_empty_folders". How can I do that in a shell script?
1
vote
3answers
859 views

Creating directories with sequential numbering

I am trying to create a sequence of identical directories with names like 'file001' in sequence from 1 to 512. I am running the following in the shell: for i in $(seq 001 512): do mkdir ...
3
votes
2answers
60 views

Delete .pdf files only if .xlsx files in directory have same filename?

I have folders with hundreds of pdf and xls(x) files that were mass exported from legal e-discovery systems. The filenames in these exports correspond to bates # such as ABCD_00000001.pdf, ...
0
votes
1answer
190 views

Always exclude path in find command

I have a directory whose contents should never be found by find, so I aliased find like this: alias find='find -not -path "*.sync*"' the issue is that find now complains that operators are not ...
2
votes
2answers
67 views

How do I create a symbol to represent a path to easily cd into a directory?

In the same way that cd ~ directs you to your home directory, is it possible to create another symbol, @ for example, such that cd @ would take me to /my/working/directory?
0
votes
2answers
28 views

Renaming directories with specific extensions

An extension to the previous question that I asked: Rename an alphanumeric file I have a directory that has subdirectories with an extension of *_upstream: DHX30_vs_Control18....
0
votes
1answer
312 views

How to pass variable in pattern while using sed command?

I have file abc.sh search_dir='dummy' filename='numbers.txt' for entry in "$search_dir"/* do while read p; do sed -i '' "/$p/d" $entry done < $filename done Trying to delete a line ...
0
votes
2answers
97 views

Copy the latest files from the directory

I have the following files in a data directory: myfile1.txt myfile2.jnx myfile3.sur. I use the below command to copy the contents of the above directory to another location: scp data/* remotehost....
0
votes
2answers
27 views

Entering the last modified directory

Which command can I use to: Enter the last modified directory in the current directory. If no directory exists or is possible to enter, do nothing. I'm looking for an alias named ca that will work ...
3
votes
3answers
737 views

How does the shell interpret ././command-name?

I have a binary file named hello2 in my current working directory. To execute it I need to press ./hello2 and it shows the output. But when I use the following command ././hello2 it still works. ...
0
votes
1answer
34 views

How can I run a shell command that executes on subdirectories in a continuous manner?

I have a directory, that contains hundreds of subdirectories. The structure looks like this: directory ---> subdirectory_1 ---> file1 | |---> file2 ---&...
1
vote
2answers
60 views

Move files from various subfolders into sub-subfolders

I have various folders each containing files as such: /.example1/example1.txt /.example1/example2.txt /.example2/example1.txt /.example2/example2.txt etc. And want to find a way to move each of the ...
2
votes
1answer
107 views

An archive with long filename inside – unarchiver hits filesystem limit and fails

I have an unarchiver that takes in an archive name, and a directory name, and dumps all files from that archive into that directory. No other command-line options. However, someone zipped a file in ...
-3
votes
1answer
58 views

How to create copies of a directory with sequential numbers

I have a template directory containing sub-directories and MS-Windows links. This directory needs to be sequentially reproduced at the same folder level. The range needs to be from one to twenty. So, ...
2
votes
1answer
42 views

How to link to original dir by linking a link to that dir?

Here is the sample $ mkdir original_dir $ ln -s original_dir link $ ls -l original_dir link -> original_dir Now I want to create a new link to original_dir by linking to link, how can I do that $...
0
votes
3answers
184 views

How to move a file from a subdirectory to another subdirectory located outside the first one?

i am at fickurthe first one and trying to move the inner fickur to digital with only one command line, but cant seem to figure this one out. here is what i have tried so far: mv -v fickur/ ./...
1
vote
1answer
414 views

Printing the number of files having the same name for every file from a directory

I am new to Linux and I have an assignment which requires writing a shell script that prints all the names of both files and subdirectories of a directory (given as parameter) and this should also ...
-2
votes
1answer
1k views

Not able to cd into folder in Linux machine. Says file/folder does not exist

I have written a test ksh file to cd into a folder and do a listing. Following is written: `cd "their_file/"`; `pwd`; `ls -l`; Gives me following output: ./test.ksh: line 2: /home/user/final: Is ...
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 ...
3
votes
1answer
78 views

New (login) shells (window) opens at $HOME rather than $PWD (like they used to) on macOS. What gives?

Every time I open a new shell window, I'm brought to my home directory rather than the current directory I was in when I gave the command to open a new Terminal.app window. I am under the impression ...
0
votes
1answer
177 views

Loop through specific set of directories

The following code loops through ALL directories under current path to perform a count on compressed xml files: for i in *xml.gz; do echo "XML" "${PWD##*/}" "$i" $(gunzip -c $i | echo "scale=0; `...
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/..: ...
0
votes
1answer
75 views

Special directory permissions for new user

I need to add special permission for new shell user. After using adduser command new, the user can read all directories into shell account. Command adduser user1 brings us new user which has own ...
2
votes
2answers
3k views

Find with mkdir and substring

I have directory with the next structure: example ├───1 │ └───01-01-2015.txt ├───2 │ └───02-02-2016.txt ├───3 │ └───03-03-2017.txt └───script.sh I'm trying to write a script which will find ...
1
vote
1answer
233 views

Is there an accepted name for referring to ~/ paths? [closed]

Is there an accepted name for referring to home directory ~/ paths? While searching for the answer I found posts which use a variety of terms: ~/ syntax ~/ paths ~/ expanded paths ~/ notation But I ...
10
votes
3answers
762 views

Is it possible to perform shell command substitution without using a subshell?

I have a scenario that calls for command substitution without using a subshell. I have a construct like this: pushd $(mktemp -d) Now I want to exit and remove the temporary directory in one go: ...
0
votes
1answer
41 views

Copy folders has specific part of name and it is content

I have a long list of folder as follow: 001_bat_3513 002_mon_3213 003_bat_3515 004_btt_3540 005_bat_4513 055_bpt_8523 056_bot_3513 058_bat_1513 . . From this list: How can I copy the folders ( and ...
1
vote
1answer
327 views

Group or world writable directory

I'm trying to use a script but get the following error: Directory is group or world writeable. This is insecure, since any malicious user can trick you to write newly generated private key into his ...
1
vote
2answers
361 views

How to get all subfolder names consisting of uppercases only?

How to get the folders in a parent folder, the names of which are composed of A-Z, without lowercases, underscore, dot or any other things?
1
vote
2answers
732 views

expand wildcards “inside a command” instead of in the shell

(This is a simplest working example of something in a much messier context.) I have a directory d with files 1.txt 2.txt 3.txt 4.wav. My current directory is somewhere else. ls d reports 1.txt 2.txt ...
5
votes
3answers
1k views

Delete directories that contain a certain file

I want to find all directories that contain a certain file and then delete those directories. With find . -name thatcertainfile -execdir pwd \; I get a list of all the directories I want to delete, ...
2
votes
2answers
6k views

Grep only in files that are in certain folders

I want to grep for interesting string, but only in specific folder/file combinations, such as myfolder/myfile.out. The directory I'm grepping from may have these combinations in subdirectories of ...
14
votes
5answers
787 views

How can I find the first missing directory in a long path?

Imagine I have a path that doesn't exist: $ ls /foo/bar/baz/hello/world ls: cannot access /foo/bar/baz/hello/world: No such file or directory But let's say /foo/bar does exist. Is there a quick way ...
13
votes
3answers
3k views

Why is it rm -rf and not rmdir -rf

I've always been curious why the command for deleting everything in a directory is rm -rf. Why aren't there flags to do the same thing with rmdir? Wouldn't it be more intuitive to use rmdir for ...
1
vote
2answers
100 views

Use “find” from a specific relative directory [closed]

Suppose I'm in the following directory: /A-dir/B-dir/mydir/… some directories …/x-dir I want find to search from mydir, but mydir is not specifically known in advance; it is defined by the current ...
2
votes
1answer
597 views

Running command on multiple files within multiple directories

I want to run the command python quast.py -o quast contigs.fasta but I want to do this for multiple contigs.fasta files in multiple directories. I'm running OSX.
3
votes
3answers
13k views

How do I write a script to count the total number of files, and directories in my home directory then display it?

I want to do it with a for loop. This is what I've come up with so far which does not work. for home in /home/ {.,/}*; do echo "$home"; done I would like to do this non-recursively if possible.
20
votes
2answers
30k views

How do I get the total size of everything in a directory in one line? [duplicate]

I know I can use du -h to output the total size of a directory. But when it contains other subdirectories, the output would be something like: du -h /root/test . . . . 24K /root/test/1 64K /root/...
2
votes
3answers
335 views

need to move files with name into directories with corresponding names

I have files named patient_sample_L001_R1_001, patient_sample_L002_R1_001, patient_sample_L003_R1_001, patient_sample_L004_R1_001 another set named patient_sample_L001_R1_002, ...