Tag Info

New answers tagged

2

The simplest way would be to get a cross-over cable and connect the two machines. :) But if you absolutely must do it with a flash memory and some duct tape, you could do it like this: On the destination machine: find /some/dir -type f -print0 | xargs -0 sha1sum -b | sort >dst.txt copy the dst.txt file to the source machine On the source machine: ...


0

With pax, to copy . into subdir/tmp, skipping subdir/tmp: mkdir -p subdir/tmp && pax -rws'|^\./subdir/tmp/.*||' . subdir/tmp Alternatively, you could do something like: mkdir -p subdir/tmp/subdir && ln -s tmp subdir/tmp/subdir/tmp && cp -a . subdir/tmp subdir/tmp/subdir/tmp is then a symlink to itself, to cp won't be able ...


1

Can tar in combination with the -N | --newer | --after parameter help you?. It allows you to backup all the files which are modified since the specified date. If you create a file list (using find for example) before each run, you can compare the files to see which files are removed. Using that output you can remove the extra files from the destination ...


1

Let's see if this will solve your problem. Make a script. FILE=`ssh abc@xyz ls -ht /tmp/*.doc | head -n 1` rsync -avz -e ssh abc@xyz:"$FILE" . This will run a command on the remote server "ls -ht /tmp/*.doc | head -n 1" and will show the latest doc. Rsync that specified file from remote server to your current directory. ssh/rsync will also ask you a ...


2

I am not really clear what your problem is, but if you're trying to copy to the current directory then just use . to refer to the current directory so that your command is: scp -i key.pem abc@xyz:/tmp/*.doc .


1

Your issue may be related with the --manage-gids option of rpc.mountd enabled by default in debian (see /etc/default/nfs-kernel-server). From the man page: -g or --manage-gids Accept requests from the kernel to map user id numbers into lists of group id numbers for use in access control. An NFS request will normally (except when using Kerberos or ...


1

This is not possible after the fact. “Normal” filesystems don't keep a log of the past versions of a file. All you can know is the last time the file was modified (that's the file's modification time, which is shown by ls -l and by most file managers). You can't find past versions or know when they were made unless the editor happened to leave a backup file ...


4

To find all files in the current directory and its subdirectories whose last modification time is earlier than 2015-05-28: find . ! -newermt 20150527 If you only want files from the current directory and not its subdirectories, use: find . -maxdepth 1 ! -newermt 20150527 How it works find This is one of unix's most useful commands when searching for ...


0

For interactive use, I have a hack for the analogous case with mv: cd .. mv * tmp mv: cannot move ‘tmp’ to a subdirectory of itself, ‘tmp/tmp’ Ignore the error, everything else got moved :-P. Doesn't work quite the same with cp, it creates an empty tmp/tmp, which is probably not what you want.


1

If you start from the parent directory, you can do this with find and GNU cp. Assuming the directory you're in currently (the one containing tmp) is called folder, and that tmp is empty, you'd run cd .. find . -path ./folder/tmp -prune -o -type f -exec cp --parents -t folder/tmp {} + This asks find to list everything under . (which is your old ..), ...


1

Try testing mkdir instead, that's what most people would be worrying about? touch doesn't create executable files. It masks those bits off in the mode parameter to sys_open(). Source code: 133 /* Try to open FILE, creating it if necessary. */ 134 fd = fd_reopen (STDIN_FILENO, file, 135 O_WRONLY | O_CREAT | O_NONBLOCK ...


0

It depends on what you mean by obfuscating.  Here's an approach that lets you wrap scripts in compilable programs, allowing you to turn them into binary executables.  Write a C program that looks like this: #include <stdio.h> #include <stdlib.h> ︙ FILE *sh; sh = popen("/bin/sh", "w"); // Use "/bin/bash" if ...


-1

Here is a nice video on all ways to delete the content of a file. https://goo.gl/l1PLAz


2

Most filesystems don't provide any means of doing this. There are a few different ways of tracking file changes on Unix/Linux systems though: Log-structured filesystems, such as NILFS, track all changes as snapshots. These snapshots are preserved as long as possible (which depends on the nilfs_cleanerd settings and the amount of changes in the ...


3

This is not possible with native files in the filesystem. What you may be seeking is a version control system, like git (or svn, etc.), where users check files out and in, and all information about the activities and changes is stored in the database of the respective version control system.


2

Try this: find / -user <someuser> -type f -printf '%s\t%p\n' | sort -rn | head -1 The above uses GNU find(1) and assumes no filenames have embedded newlines. It also has to be run as root (otherwise it wouldn't be able to read all directories).


2

You can use the find command for this. To search your entire filesystem for files owned by user exampleuser use: $ sudo find / -user exampleuser If you want search for large files add the -size option: $ sudo find / -user exampleuser -size +10000k This: +10000k will find files greater than 10,000 kilobytes in size.


2

Did a bash command based on the response of Matteo :) Code: chmod $( stat -f '%p' "$1" ) "${@:2}" Usage: cp-permissions <from> <to>...


2

On Linux, assuming that none of your file names have _create inside them (only at the end), you can use the rename utility from the util-linux package, which is installed on all non-embedded Linux systems. Call find to execute the command on all files in subdirectories recursively. find -depth -exec rename _create _bak {} + On Debian and derived ...


1

Be careful with special file names (spaces, quotes) when piping to rm. There is a safe alternative - the -delete option: find /path/to/directory/ -mindepth 1 -mtime +5 -delete That's it, no separate rm call and you don't need to worry about file names. Replace -delete with -depth -print to test this command before you run it (-delete implies -depth).


-1

First off, that isn't how you pipe something to grep. Also, it is generally considered better form to separate commands from the conditional and just check return codes. Something like the following works perfectly: command=`ls -l` for file in "$command" do echo "$file" | grep 'o' if [ $? -eq 0 ]; then echo "$file" fi done


1

On Debian, Ubuntu and derivatives, with the Perl rename, sometimes installed as prename: #enable ** globbing shopt -s globstar #use the rename utility rename -n 's/_create$/_bak/' **_create Remove the -n (= --no-act) flag if it works as expected. Note: This is probably the shortest efficient way to do this, especially if you've got shotp -s globstar ...


0

This may be what you're after: for file in $(find . -name "*_create"); do mv -i $file ${file%%_create}_bak; done Be sure to test it before using it on real files.


-1

I have an alternate solutions for this situation. Lets say you have 1000 inodes in a partition of 10G. But due to inodes limit you are not suppose to use all space of partition. But in this solutions you will be able to use the remaining space of the partition without formatting it. $ df -i # see list ( I need just one free inode here so move just one file ...


1

You probably should use a batch tool for batch operations. Doing so will usually entail reading/writing all records in a single stream rather than, for example, invoking a separate cp process for each file copied. There is already a cpio answer written here, which, given only the options already provided you is likely what I would choose. However, the cpio ...


10

$file | grep -o executes the command specified by the value of file and pipes its output to grep. But that's clearly not what you wanted. If you want to list files that contain o You meant the value of file to be an input file for grep, not a command to execute. So you need an input redirection, not a pipe. if grep 'o' <"$file" grep reads from ...


1

You should not rely on ls output at all. ls is meant to show human friendly output and not to be used within scripts. See the following example; for f in ./* do if [[ $f = *o* ]]; then printf '%s\n' "$f" fi done


5

You're trying to execute $file. Instead, you must echo it: # ... if echo "$file" | grep 'o' ; # ... Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null). You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against ...


1

I think maybe this issue is very the same as yours, you also can check this out: Create sub-directories and organize files by date I write this new script based on that issue's first answer: for x in *; do d=$(date -r "$x" +%Y) mkdir -p "/your/new/directory/$d" mv -- "$x" "/your/new/directory/$d/" done write this script to a file named copy.sh in ...


4

If you have newer files on the old disk that you want to ignore I would go about it like this Create a temporary marker file with a modified-by date that separates files I want from those I don't Copy files older than the marker file to the new location Here are sample commands for this, which assume you want to maintain any directory hierarchy from the ...


4

Do not use ls. It's not recommended to use in such cases. Moreover using grep to filter according to date is not a good idea. You filename might itself contain 2012 string, even though it was not modified in 2012. Use find command and pipe its output. find . -newermt 20120101 -not -newermt 20130101 -print0 | xargs -0 cp -t /your/target/directory Here, ...


5

Brendan Gregg's iosnoop (part of his perf-tools) will give you detailed information about an application's I/O; for example: # ./iosnoop Tracing block I/O... Ctrl-C to end. COMM PID TYPE DEV BLOCK BYTES LATms supervise 1809 W 202,1 17039968 4096 1.32 supervise 1809 W 202,1 17039976 ...


3

Whilst monitoring logging I have to go to my log files, order by written date, so I can then see the name of the log file for the most-recent execution of my application. I assume this means that the application writes log files like this: AFile1.log AFile2.log AFile3.log AFilex.log Is there any way, given a directory and sub-string, to return ...


3

The -q option to diff makes it only list the names of files with differences (or missing from one of the directories): diff -q folder1 folder2


3

You may try inotify (often packaged inotify tools since kernel 2.6). It will monitor a part of your filesystem and inform you on events like creating/deleting files or directories. A simple use would be: inotifywait -m -r /tmp/ Then, when filesystem activity occurs, you'll see: #=> I'm creating /tmp/b /tmp/ CREATE,ISDIR b /tmp/ OPEN,ISDIR b /tmp/ ...


2

awk awk 'FNR==NR { a[$2, $3]=$4 next } ($2, $3) in a{ print $0, a[$2, $3] } ' file2.txt file1.txt > out.txt join join -j 2 \ <(sort -k2,3 file2.txt | sed 's/ /+/2') \ <(sort -k2,3 file1.txt | sed 's/ /+/2') \ -o ...


1

cat file: 22 z there's a moose loose in the hoose eg. Set args to: loose moose - read by script as "$@" You can use as many as you like. by=( "$@" ) nl file | sed -nf <(for ((i=0;i<${#by[@]};i++)) ;do echo "s/.*${by[i]}.*/$i\t&/; t p" done; echo "s/^/$i\t&/; :p p") | sort -nk1 -nk2 | ...


1

In your example you are creating array m with values 0. You nowhere set it to 1, and you don't need to. You can just set value to entire row, e.g $0. Try this: awk 'FILENAME == ARGV[1] { m[$2,$3] = $0; next; } { if (($2,$3) in m) { print m[$2,$3] " " $4 >"out.txt"; } }' file1.txt file2.txt


1

Answer: @derobert pointed out the "sox" and "play" command are part of the same package but does different thing. The 3600 below is the time interval in seconds. sox -n note.mp3 synth 3600 sin 347 The above code will generate an hour long tone without playing it. play -n note.mp3 synth 3600 sin 347 The above code will play the tone for an hour AND ...


2

With sqlite and ORDER BY clause: $sqlite3 <<\EOT CREATE TABLE file(line); .import file.txt file SELECT * FROM file ORDER BY CASE WHEN line LIKE '%USB%' THEN 0 WHEN line LIKE '%Realtek%' THEN 1 ELSE 3 END; EOT 00:10.0 USB controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 81) 00:10.1 USB controller: VIA Technologies, ...


5

It sounds like you want a scoring system.  Write a script to assign a score to each line, indicating how early in the output you want to see it.  awk seems well suited to this job.  For your example: #!/bin/sh awk '{score=0} /usb/ {score=1} /Plantronics/ {score=2} {print score, NR, $0}' "$@" This assigns a score of 0 to every line by default, ...


2

What you're doing isn't really sorting, but selecting. So what you'd want to do is first select all the lines that contain "Platronics", then all the lines that contain "usb", and so on, and finally all the lines that don't match anything. I don't know of a command that does this in one go, but you can write a little script using python that does what you ...


4

chgrp is to "change the group ownership of a file or directory". Thus, you can't change user ownership with that command (use chown instead, which can change user and group ownership) If your folder fruit is in 777 mode, obviously, anybody can create a sub-folder inside it. This sub-folder will be owned by the user who created it, so in your case, the ...


3

The command chown needs root permission when transferring ownership to other users. chgrp is irrelevant since it only affects the group, not the user. You can't obligate someone to take a file from you if he doesn't want. If you are a root or with root permissions then you are the commander and you can do whatever you want. Instead as a workaround, you can ...


1

If you have a GNU find you can use -printf option find `php-config --extension-dir` -name "*.so" -printf 'extension=%f\n'


2

How about this? find "`php-config --extension-dir`" -name "*.so" | sed 's!^.*/!extension=!' For each line, sed will match the longest string that starts at the beginning (^) and ends at /. It will always match everything up to and including the last /, because it is a greedy match, i.e., it will match everything but the filename. It then replaces that ...


0

I see there is no answer, so my suggestion sort -k2,2 -nk3,3 file


2

If you so like awk awk ' FILENAME != ARGV[3] { m[$2,$3] = 1 next } !(($2,$3) in m) ' file3.txt file2.txt file1.txt > out.txt As for me much easy cut -d" " -f 2,3 file2.txt file3.txt | grep -v -f - file1.txt > out.txt


0

The default standard input handling of ssh drains the remaining line from the while loop. To avoid this problem, alter where the problematic command reads standard input from. If no standard input need be passed to the command, read standard input from the special /dev/null device.


1

Possible solution with awk: awk 'FILENAME == ARGV[1] { m[$2,$3] = $0; next; } FILENAME == ARGV[2] { if (!(($2,$3) in m)) { m[$2,$3] = $0; } next; } { if (!(($2,$3) in m)) { print $0 >"out.txt"; } }' file3.txt file2.txt file1.txt First we read the first file and create array with keys column 2 and 3. Then we ...



Top 50 recent answers are included