6
votes
2answers
277 views

How to find out which program can open a given file?

Let's say I have a file thesis.pdf or picture.jpg Is there a command which returns a program to open this file with? I am aware of the command file, but it just returns the correct type of the file ...
4
votes
2answers
62 views

How to redirect stdout to a file and read from the same file simultaneously with another task?

I want to run a task (which takes quite a long time) remotely in Ubuntu Linux Bash via nohup and redirect stdout to a file, e.g.: nohup task > out.txt & From time to time I would like to ...
0
votes
1answer
117 views

How do I cat a command file?

I have the output of the crontab -l stored in a file (crontab_file) with no extension. But whenever I try to cat it, I get errors saying command not found for multiple line of the file. Here is the ...
4
votes
3answers
113 views

zsh's “echo SomeText >> **/filename” in other shells

I need to fill all files with a specific filename (recursively) with a text. In zsh this can be done with echo SomeText > **/TheFileName I search generic solutions for sh-compatible and/or tcsh ...
2
votes
4answers
69 views

Get the latest directory (not the latest file)

My folder parent has the following content: A.Folder B.Folder C.File It has both folders and files inside. B.Folder is newer. Now I just want to get B.Folder, how could I achieve this? I tried ...
2
votes
5answers
512 views

How to use the sed command to only show the first column and last column in a text file

I need some help to figure out how to use the sed command to only show the first column and last column in a text file. Here is what I have so far for column 1: cat logfile | sed 's/\|/ /'|awk ...
4
votes
4answers
157 views

What is the Linux command to display how many file names in the directory end in two digits

What is the Linux command to display how many file names in the directory end in two digits? Using ls with a command like this : ls -l | wc –l *[0-9][0-9]
5
votes
4answers
323 views

Check if a folder has a certain type of file present

How could I check if a file has a file of extension .java? So far I have: for javaFile in *.java ; do { echo "The file $javaFile has : " >> ~/Desktop/externalServers.txt ...
1
vote
1answer
38 views

Is there a command which creates a temporary file containing the arguments passed to it?

I can paste the contents of a file into a command using cat and backticks: ls `cat filenames` Is there a way to do the reverse - to turn a string into a (temporary) filename? gcc -o cpuburn `uncat ...
2
votes
2answers
116 views

find the single largest file

We host a share of size 4 TB. How efficient is it to find a file with highest size. Usually we use: du -ak | sort -k1 -bn | tail -1 and it is not easy to scan through a share of such huge size and ...
14
votes
3answers
2k views

Why isn't there any shell command to create files?

Attention please: I am not asking how to make a file from the command line! I have been using touch for making files for years without paying attention that its main purpose is something else. If ...
1
vote
2answers
55 views

tar specific files based on a pattern

I got a lot of files with the following format: 2014_04_01_11.txt 2014_04_01_12.txt 2014_04_01_13.txt 2013_03_25_12.txt 2013_04_29_15.txt I would like to tar all theses files into an archive 20?? _ ...
3
votes
1answer
59 views

Merging text files based on their filename

I have hundred of files with the following format: 2013_01_19_xyxyxyx.txt 2013_01_19_xyxyxyx.txt 2014_03_21_xyxyxyx.txt 2014_03_21_zxzxzxz.txt 2014_03_22_abababa.txt 2014_03_22_cbcbcbc.txt etc. I ...
2
votes
4answers
96 views

Can a running script identify the logging context?

Let us say I redirect the STDOUT, STDERR of a program to files. ./script.sh 1> output.log 2> error.log Can the running program find this out i.e. know the paths to these files?
1
vote
1answer
76 views

List files, directories and executables in current directory

I have php shell and I have function that do just that (but it give me error when I call scandir($path) function because of restriction in php), so I need to use my bash shell to do the same. It can ...
2
votes
1answer
132 views

remove duplicate files in 2 directories

I have two folders (w/ subfolders) containing files that both contain essentially the same content. Example: /folder/files/data/new /folder/files/data/old Is there way to delete all files in /new ...
3
votes
3answers
501 views

Efficient way to create multiple files

I have been testing find directory which is taking max inodes and while testing I had run touch test_{1..1391803}.txt But it's give me error "-bash: /usr/bin/touch: Argument list too long", now ...
0
votes
1answer
115 views

Updating last modified time of a file

I have created a script to read 15 pcap files from a folder and merge then into one file using mergecap command. I want the merged file to have the creation time same as the first file of the 15 files ...
1
vote
2answers
176 views

Free disk space from a JBoss log file which is still being written to

Is there any locking on the content, imposed by the process if at all the process is using the file. We host a JBoss app server on a RHEL 6.4 OS and due to the disk space constraints we have decided ...
0
votes
1answer
48 views

Capture Error of LS to file [duplicate]

#!/bin/sh if [ $(ls sample01.log | wc -l) = 1 ] then echo "File Found" > lsOutput.log else echo "File Not Found" > lsOutput.log fi But if sample01.log is not already existing my code already ...
2
votes
1answer
235 views

Copy files based on date/time from subset of directories

I'm teaching a class where (~80) students are submitting assignments that I can access via webdav, organized by student in directories named by their unique identifier. The students are split into ...
2
votes
2answers
94 views

How to change “date modified” of multiple folders, to be the same of that of a .mkv that's inside each one, using Cygwin

How to change "date modified" of multiple folders to be the same of that of the .mkv that's inside each one. eg. there's folder1 which contains a file 1.mkv folder1: 2/17/14 1.mkv: 1/6/12 I want ...
2
votes
2answers
547 views

delete old log files except the last one (alphanumerically sorted)

I have a number of log files in the form: log.2014-02-19-10_24_22 I.e. log.YYYY-MM-DD-H24_MI_SS The date that's part of the log file's name is when the log file was first created. So at any given ...
2
votes
1answer
39 views

Ignore file changes

I have a process, which generates a file with configuration data and then calls a subprocess with this data as parameter. I'd like to override the configuration data, which is passed. The problem is, ...
2
votes
1answer
95 views

Compressing all files that contain a particular string

How can you compress all files in a directory that contain the word “compress” anywhere within its contents?
-11
votes
2answers
162 views

Count the number of executable programs in a directory [closed]

How can I count the number of executable regular files in the current directory in a shell script?
8
votes
4answers
1k views

Grep from the end of a file to the beginning

I have a file with about 30.000.000 lines (Radius Accounting) and I need to find the last match of a given pattern. The command: tac accounting.log | grep $pattern gives what I need, but it's too ...
6
votes
5answers
814 views

How does one find out how many bits a file has in one command?

I know I can use ls -lat to find out how many bytes has a file and then multiply by 8 to find out how many bits. But is this possible in only one command line?
0
votes
1answer
102 views

Passing multiple scripts to shell over ssh

I have a somewhat lengthy script which sources other scripts to include the functions there. I'd like to execute this script remotely via ssh. Now I thought to make one script file of it (without ...
3
votes
2answers
334 views

grep string from contents of file command then delete file

I have a peculiar problem I need help with. I have a large batch of .docx files where a certain number of them are junk. I know how to identify these files from the file command, as they contain the ...
0
votes
1answer
57 views

Check multiple directory properties

I'd like to make this test as fast as possible: (Bash) if [[ -d $directory_path && -r $directory_path && -x $directory_path ]]
5
votes
5answers
338 views

Number of files not containing given string

I read the question about how to find out the number of files that contain a certain string. This is possible with grep -l "string" * | wc -l. Is it possible to invert this, finding the number of ...
3
votes
3answers
1k views

How to delete 2 months back files in unix

Say I have below log files, AA_XX_20130719185428.log exec_xxx_cpb_20130712182453.log 13122013121327_AR_INC_DOBC_1.dprf.log 24122013_masterscript.LOG Date part contains both date and time. I want ...
2
votes
2answers
89 views

Replicate a directory and file names n times

I have folder which has some data (files) in that with the name 201311261418 And a file 201311261418.eob In my scenario I need to replicate this folder and file names n times with the appended ...
4
votes
2answers
4k views

Remove all files created before a certain date

I have a directory containing a high number of files (like logs for every day of the year). I would like to remove all files created before let's say 22/11. How can I achieve that ? Must I use find ...
0
votes
2answers
93 views

Using Pipeline to Direct Files to Program that Opens Them

I have a Music folder, in which I have some music tracks, which aren't organized too well. Thus, if I want to find a particular track, I usually type: ls Music | grep <keyword>, where ...
1
vote
2answers
133 views

Display the number of bytes, words and lines in a file

I want to create a shell script df. As, I want to type in df name_of_file and then I can get the contents of the file. If the file name is in the directory, I want it to show its contents. If not, I ...
2
votes
1answer
105 views

Why does copying from a script screw with my files?

I am at a loss here, trying to find out the reason why a shell script that is basically copying a couple of files and directories from one place to another will result in the content of two of the ...
1
vote
1answer
65 views

multiple conversion bam to bed using bedtools

I have ten .bam files (bioinformatic format) and I would like to convert it to 10 .bed files, but for this conversion I need to use special command bedtools bamTobed -i (input file) > output ...
2
votes
4answers
144 views

How to start processing a file at an offset?

Use case: You've got a multi-GB log file for a whole week, and you need to search for something which happened on Saturday using for example grep. Making an educated guess, you assume that starting ...
1
vote
4answers
596 views

monitoring file changes + process access to files

I would like to see what's happening in my app server folders, which files are changed by process x or which *.war files has been changed (replaced/created) in last x minutes. I am software developer ...
0
votes
3answers
4k views

need to move files to different folder based on the creation date [duplicate]

I have set of files created from Monday to Friday.. a -- > 08/20 a1---> 08/21 a2---> 08/21 a3---> 08/21 a4---> 08/22 a5 --> 08/23 I need to move only 08/21 file to diffrenet ...
1
vote
2answers
906 views

Find and move directories based on file type and date

I have a directory "New Movies" containing 200+ subdirectories "Movie Name (year)". The subdirectories "Movie Name (year)" contains a single video file (avi/mkv) and several related jpg/xml files. I ...
5
votes
3answers
312 views

Getting relative links between two paths

Say I have two paths: <source_path> and <target_path>. I would like my shell (zsh) to automatically find out if there is a way to represent <target_path> from <source_path> as ...
2
votes
2answers
115 views

Is it possible to create a “file” that can be used by any process without actually saving the file on disk?

Suppose I do a grep that gives me a lot of results. I want to use the output of grep and pass it to a command that takes a filename as it's first argument. For example - myCommand filename.txt I ...
-1
votes
3answers
185 views

How can I pass a whitespace-delimited values file as a series of arguments?

Say that I have a file with a list of packages I want to install, separated by spaces or newlines. How can I pass that file to my package manager?
1
vote
2answers
88 views

how to count number of differences in large streams quickly?

I want to count the number of differences (different bytes) in two large streams (devices/files). E.g. two hard disks, or one hard disk and /dev/zero. The program(s) involved must be fast, as fast ...
1
vote
4answers
231 views

Command substitution grepping ls output causes error

I'm trying to make a tar.tgz file using command substitution There are backups of 17 Aug 2012 -rw-r----- 1 ossec 502 804M Aug 17 2012 BKPMDISINT_i6nir20j.F_bkp -rw-r----- 1 ossec 502 2.7G Aug 17 ...
8
votes
2answers
2k views

how to output text to both screen and file inside a shell script?

Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file ...
2
votes
2answers
2k views

Linux listing files between two date without touch command

I need a command which will list the files between given date and time (YYYYMMDDHHMMSS - format) in to a text file. I don want to use touch command as its creating permission issue. I am new to this ...