Tag Info

New answers tagged

0

You do not need to use the /etc/passwd file. If user directories are in /home, and if you have root privilege, you can use find as find /home -name cat.sh -exec ls -l {} \; If you want to see the time of last use, you can specify the option as -lu.


0

You can use fswatch, a portable tool which selects the appropriate event mechanism if available (Linux, Mac, *BSD) or just stat(2) elsewhere. I did not write it, but I use it. It's open source (GNU GPL). Example usage: fswatch -e '.' -i '\.end$' . | while read file do # Get rid of removed file events ls $file 2>/dev/null || continue echo ...


1

From a user's perspective, a nice & simple Unix tool that does the job perfectly is qsubst. For example, % qsubst foo bar *.c *.h will replace foo with bar in all my C files. A nice feature is that qsubst will do a query-replace, i.e., it will show me each occurrence of foo and ask whether I want to replace it or not. [You can replace unconditionally ...


4

# ls -lLh MyLog_nohup.out -rw-r-lr-- 1 user group 72G Jul 30 07:26 MyLog_nohup.out # du -sh MyLog_nohup.out 480K MyLog_nohup.out This looks like a sparse file to me. A sparse file allocates a virtual size on the disk (72G in your case) for efficiency but in reality the used space is as much data that is written on the file (480K in your ...


4

Your file is not corrupted; On Linux and POSIX systems, as long as a running process has an opened file descriptor to some file that it is writing, it will be able to continue writing it, even if you remove or rename that file (because a file descriptor is related to an i-node, not to a file name). in particular logrotate or logadm -or any sequence of ...


3

While chaos's answer is good to be used in interactive shells, this one can be used as a POSIX script, for example if you need to do this periodically and/or do it on another computers. #!/bin/sh i=0 while test "$((i+=1))" -lt 366 ; do for j in 00 06 12 18 ; do file="GLDAS_NOAH025SUBP_3H.A2003$(printf '%03d' ...


5

A variation on @chaos solution (bash 4.0 or above or zsh 4.3.11 and above): for a in GL.....2003{001..365}.{00..18..6}00.001.2015210044609.pss.grb do [[ -f $a ]] || echo "$a" done or for a in {001..365}.{00..18..6} do [[ -f "GL.....2003${a}00.001.2015210044609.pss.grb" ]] || echo "$a" done to print only the missing day+hour


10

With zsh or bash4, you can use brace expansion for that: ls -d GLDAS_NOAH025SUBP_3H.A2003{001..006}.{0000,0600,1200,1800}.001.2015210044609.pss.grb >/dev/null Notice the brackets: {001..006} means expand to 001, 002, ... 006 {0000,0600,1200,1800} to every one of the above add 0000, 0600, 1200 and 1800. >/dev/null is to avoid the standard output of ...


2

Build the file names in a loop and then test for non-existence of a file: for day in `seq -f "%03g" 1 30` do for hour in 0000 0600 1200 1800 do filename="GLDAS_NOAH025SUBP_3H.A2003${day}.${hour}.001.2015210044609.pss.grb" if [[ ! -e $filename ]] then echo "File missing: $filename" fi done done Note: I do not guarantee this ...


3

Assuming you have sufficient permissions to delete the file, simply deleting with the rm command should be sufficient: rm <filename> Note that the size of the file is irrelevant. When you delete a file, it typically isn't wiped in its entirety - instead the inode that points to the disk space is simply marked as unused. The disk space is then ...


1

I do not remember doing anything that day that may have generated these files, nor did I download them as I don't even know what these files are or why they're there. You can have a look at history, maybe there is a clue and you remember what could have caused this. Since these files look a lot like they are part of your system, you can try to locate ...


0

At the moment on RHEL7.1--I'm not sure if this has always been there and I missed it--I can execute the following to get a list of all the filecontexts and just pipe the output to grep: # semanage fcontext -l |grep ifconfig_exec_t /bin/ip regular file system_u:object_r:ifconfig_exec_t:s0 /sbin/ethtool ...


0

You can use this little systemtap script : #!/usr/bin/stap function proc:string() { return sprintf("PID(%d) UID(%d) PROC(%s)", pid(), uid(), execname()) } probe syscall.open.return, syscall.stat.return, syscall.open64.return ?, syscall.stat64.return ? { filename = user_string($filename) if ($return < 0) { printf("failed %s on %s by %s\n", ...


0

Something like this should do it: strace -f \ -e trace=open,stat,stat64,lstat,lstat64,chdir,mkdir,rename,symlink,creat \ -o >(grep "the paths you want to catch" > log) \ commandToStartYourServer You want the -f switch to track children processes. The trace options are a subset of what fabricate uses to trace IO (fabricate traces ...


2

Answering the second part of your question, the "best" way to watch for filesystem changes is by using inotify(7). There is a set of utilities that can hook into the kernel interface, inotify-tools. In particular, you want inotifywait from that set of utilities: inotifywait efficiently waits for changes to files using Linux's inotify(7) interface. It ...


1

ls -d */ | while read d do echo $d done


2

Beware that choroba's solution, though elegant, can elicit unexpected behavior if no directories are available within the current directory. In this state, rather than skipping the for loop, bash will run the loop exactly once where d is equal to */: #!/usr/bin/env bash for d in */; do # Will print */ if no directories are available echo $d done ...


0

File does not need to be wiped of you insert one line afterwards, just insert the line with ">". @terdon something with xargs or parallel would work too: http://stackoverflow.com/questions/845863/how-to-use-in-an-xargs-command I'm fine with this comment-answer getting merged into yours :)


6

# rm -rf /path/to/undeletable rm: cannot remove ‘/path/to/undeletable’: Is a directory rm calls stat(2) to check whether /path/to/undeletable is a directory (to be deleted by rmdir(2)) or a file (to be deleted by unlink(2). Since the stat call fails (we'll see why in a minute), rm decides to use unlink, which explains the error message. # rmdir ...


2

There are two common approaches for this: find and shell globbing. find has an -exec option which lets you specify an action to be performed on each of its results. It makes each of find's results available as {} and you can modify them as you wish. It's slightly more complicated when you want to give arguments (such as echo foo > file). For that, you ...


2

Given the following tree (empty abc.txt): . ├── zyz │   └── abc.txt ├── zyz-1 │   └── abc.txt └── zyz-2 └── abc.txt You can list all the abc files with: $ echo zyz*/abc.txt zyz-1/abc.txt zyz-2/abc.txt zyz/abc.txt And you can use tee -a to append some input stream to all of those files at the same time: $ echo 'New line data' | tee -a ...


1

A pipe, just like any file, is a stream of text (more precisely, a stream of bytes). The basic building blocks of Unix tend to be simple. Interactions between processes are mostly based on unstructured data. The operating system doesn't provide a communication channel with multiple streams labeled by a file name. If programs need this, they need to arrange ...


1

Are you talking about program1 file1.txt | program2 | program3 > folder/file1.txt program1 file2.txt | program2 | program3 > folder/file2.txt program1 file42.txt | program2 | program3 > folder/file42.txt program1 green.txt | program2 | program3 > folder/green.txt program1 indigo.txt | program2 | program3 > folder/indigo.txt program1 ...


1

The more I read this question, the less sure I am that I understand it.  I’m going to assume that it is as follows: You have a directory tree that looks like . ├───dir1 ⋯ Modified 140 days ago. │ ├───dir11 ⋯ Modified 160 days ago. │ ├───dir12 ⋯ Modified 140 days ago. │ ├───dir13 ⋯ (Don’t care.) │ ├───dir14 ...


1

You have the commands, so put them in a script! To run a bunch of commands on different data, put the changing data in a variable. To run gcov and mv on all the files, there are several possible methods, including: Run gcov on all files, then move them. Run gcov on one file, then move its output. Run gconv on the files in a directory, then move them. ...


0

This doesn't answer the exact question asked, but an alternate solution is to have the log live on a different server / VM, make it append-only using chattr +a and then mount it over the network. This is not without drawbacks, but in my opinion is one of the best approaches to solving this problem.


1

If the a_a part is constant and you're running Linux, then you can use the rename utility. On Debian and derivatives, change rename to rename.ul as the rename command is a different utility which can also do this job but has a different syntax. Iterate over the directories with a loop: for d in */; do … done Call rename to rename the files in each ...


4

You are right in assuming that lsof uses the inode from the kernel's name cache. Under Linux platforms, the path name is provided by the Linux /proc file system. The handling of hard links is better explained in the FAQ: 3.3.4 Why doesn't lsof report the "correct" hard linked file path name? When lsof reports a rightmost path name component ...


1

In the unlikely event that your filesystem is mounted with strictatime or lazytime you could use: find /tools -atime +365 However if your filesystem is mounted with relatime, then this information is not being recorded. This is usually done for performance reasons. You can check using the mount command: $ mount /dev/sda3 on / type ext3 ...


1

use the find command with the -size option, a + means greater than: find dir1 dir2 -mindepth 1 -type f -size +100k -printf '%h\n' | sort | uniq -c -mindepth for excluding the dir itself, -printf for printing directory name only, uniq -c for counting the times a dir appears, type for files only, sort as find's output is not necessarily sorted.


1

With zsh: autoload zmv # best in ~/.zshrc cd /something/server/user/other_stuff/more && zmv -n '(*)/a_a(_*)' '$1/$1$2' Remove -n (dry-run) if happy. Or from /something/server/user looking recursively for a_a_* files: zmv -n '(**/)(*)/a_a(_*)' '$1$2/$2$3' (note that it doesn't look into hidden dirs, add a (#qD) to the end of the pattern for ...


1

I came up with this so far. var=("${PWD##*/}") sed -i "s/a_a/$var/g" filename


1

set '%s_q1.out %s_q2.out %s_q3.out\n' :|for d in several directories do cd -P -- "$d" || ! break set "$1" "../${PWD##*/}" { sed -ne'\|\( \.\./a_a_q[123]\.out\)\{3\}|q;s/.//p' printf "$@" "$2" "$2"; cut -c2- } <<-IN >./infile $(paste -d\ - ./infile) IN done That should work with a POSIX ...


1

In two steps in bash here is a way - epwd=$(basename `pwd`) sed -i "s/a_a/$epwd/g" <filename> The variable $epwd contains an escaped directory name, that can be taken to sed. And the sed command substitutes all occurrences of a_a by the working directory EDITED : The first line of the original answer has been edited to just have the current ...


0

You're starting out too big. Starting out with small pieces of code that you've made sure work is better. Why start with a daemon right away, and why that weird signalling to invoke poll_kbd. In C, you should be checking error codes too. Rant finished. Now why it's not working: This >>f = fopen(LOG_FILE, "w"); truncates the log file in each kbd_poll ...


1

simulation.py: (output 10 lines every second) #!/usr/bin/env python import time i=0 while True: print("{} what up {}".format(i,i%10)) if i%10==9: time.sleep(1) i+=1 In one terminal: $ stdbuf -oL python simulation.py >> log.txt In another one: $ tail -f log.txt #10 new lines every second


0

So, to (finally) answer your actual question ... for 1.6 (or later) see the excellent answer noted (http://unix.stackexchange.com/a/79411/22565), else ... you're already doing as best as can be done - there is no "don't delete my file" option, except, as you noted, via -c. In my case I have to do gzip -dc {file} | tar xvz. Don't ask me ... (alias ...


0

That's an interesting observation; the only concrete evidence I could find, so far, is this SCAP mailing list thread talking about the change from RHEL5's default permissions of 0400 to RHEL6's default of 0. You can also observe that in the list of Common Configuration Enumartions on the Working Group's now-archived website.


3

...per your comment on the question... pax -rws'/\.JPG$/.CAP&/' /root/of/copied/tree /dest/path If .jpg and .JPG are your only issues, that should just work. You can also add a print primitive to the filename substitution to get a list of all of those filenames which were changed: pax -rws'/\.JPG$/.CAP&/p' /root/of/copied/tree /dest/path As ...


1

Here's a brief stab: # for f in $( find yoursourcedirectory -name \*.jpg ) ; do cp ${f} yourtargetdirectory/${f}.CAP1.jpg ; done then # for f in $( find yoursourcedirectory -name \*.JPG ) ; do cp ${f} yourtargetdirectory/${f}.CAP2.jpg ; done This will take all the files named *.jpg in the source, and copy them over as *.CAP1.jpg and all of the *.JPG ...


0

One way to do it, assuming you have (1) a grep smart enough to read patterns from stdin, (2) a shell smart enough to handle <(...) constructs, (3) rename from the Unicode::Tussle Perl package, and (4) a collection of files without newlines in their names: cd /path/to/pics ls -1 | tr A-Z a-z | sort | uniq -d | fgrep -ixf - <(ls -1) | \ rename -n ...


-1

I know this is an old question, but it might help somebody with the same issue. When you are using a file somewhere else (for instance in a different tab), removing the folder containing that file results in the Device or resource busy-error. You can get over this error by simply exiting the program that's using the file.


0

The shadow file is specifically designed to be read ONLY by root. The point in this file is to prevent people from seeing your encrypted passwords because there are commands like "crack" than can figure out many passwords from their encrypted values. Prior to introduction of the shadow file the encrypted passwords were stored in /etc/passwd and ...


2

I realized that I forgot to mention that I aborted cp -a after checking the destination in another terminal as I was copying 300+ gb of data. Thanks to Gilles' comment I started testing to see whether it only happens to directories or not. As the tests prove below, basically all files are written as root and the old attributes are applied to the ...


1

That looks very odd to me - what you described is definitely not a known issue. I've used cp -a extensively (including to clone entire Linux systems) and the only time I've seen a problem, it was caused by a bug in XFS (which was later fixed). My guess is that it's a bug in btrfs, which is still undergoing extensive development. Is it reproducible? Can you ...


0

Checksum will also help to prevent corrupted download due to the following situation: The server has an internal error while serving the download hence the download is terminated. When that happens, there are a few possible outcomes: Good server - the server's implementation of Chunked transfer encoding is not buggy: Good client (like cURL, wget) will ...


0

First extract the video frame you desire into an image + then crop the image. To extract a frame where you know the timecode of the exact frame... ffmpeg -i my_clip_1280_720s.yuv -ss $frame -r 1 -f image2 image.jpeg To extract all frames so you can review each one + pick a frame... mkdir work ffmpeg -i my_clip_1280_720s.yuv -ss $frame -r 1 -f image2 ...


2

sed 's/=\([^= ]*\) *$/(\1)&/' <in >out The above will just replace the last equals sign on a line and all characters which follow first with... A copy of those that follow and which are not space surrounded by two parens (in case there are any trailing spaces on a line) The whole matched pattern all over again. On the right-hand-side (the ...


0

$ cd $SOURCE_DIR $ mv `ls -p| grep -v /` $Target_dir Execution Steps Move to Source directory using cd command. ls -p suffixes "/" to all the directories. grep -v is used exclude the directories and to get the regular file. Finally moving all the files to the target directory.


2

Suppose all the data is there in a file named as file, then awk -F "=" '{print $1"("$2")="$2}' file



Top 50 recent answers are included