New answers tagged

0

This script may help. (please remove the echo to actually mv files): #!/bin/bash shopt -s nullglob month=(Jan Feb Mar May Apr Jun Jul Aug Sep Oct Nov Dec) for y in 2016; do for m in {01..12}; do fn="$y-$m" dn="${month[10#$m-1]}_$y" [[ ! -d $dn ]] && mkdir -p "$dn" for file in ./"$fn"*.wav; do echo ...


0

### capitalization is important. Space separated. ### Null is a month 0 space filler and has to be there for ease of use later. MONTHS=(Null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) cd /your/ftp/dir ### pretty obvious I think for file in *.wav ### we are going to loop for .wav files do ...


0

This is not a command-line answer, per-se, but on the assumption that you have bash version >= 4 available, here's a bash script that gathers all of the *.txt files, determines their numbered suffix, then saves the highest-numbered suffix seen into an associative array (indexed by the base part of the filename before the numbered suffix). It the prints back ...


0

What is the output of df? Try monitoring the directory using inotifywatch inotifywatch -v -e modify -e access -r /home/ubuntu/analytics


2

With zsh: typeset -A greatest for f (*-*(n)) greatest[${f%-*}]=$f cp -- $greatest /destination *-*(n): non-hidden files whose name contains a - (*-*), sorted numerically ((n) glob qualifier). ${f%-*}: part of the filename up to the right-most - (or to the end if there's no -). $greatest: expands to the non-empty values of the associative arrays. So here, ...


0

I'd split the file into tab-delimited parts for more reliable, customizable filename parsing, then use awk to find the highest rank of each and report. Try each part of the pipeline first before proceeding to next! find DIR -type f <other find criteron> -print | perl -lne 'print join("\t",(/^(.*?-)(\d+)(\.\w+)$/))' | awk -F\\t '$2 > f[$1] { ...


1

If pwd is the source dir cp -t /path_to_destination $( ls -v *[0-9].txt | sed 'N;/\(.*\)[0-9]\+\.txt\n\1[0-9]\+\.txt/!P;D') NOTE: If there are any spaces in file names it should be prepared before by escaping to proper operation. + see other restrictions in Stéphane Chazelas' comments


1

files=(*) mapfile -t prefixes < <(printf "%s\n" "${files[@]%-*}" | sort -u) for p in "${prefixes[@]}"; do ls -v "$p"* | tail -1; done name_file-3.txt some_other_file-2.txt And then to copy those to some other directory: for ...; done | xargs cp -t /destination/directory


1

This script may help: for file in *-min.png; do echo mv "$file" "${file%-min.png}.png" done Remove the echo to actually execute the command.


0

That depends on your shell. I use zsh, and this is the way I do it: for i in *-min.*; do mv $i "${i%-*}.${i#*.}"; done I advice checking out the manpage of your shell, and checking out a section similar to "parameter expansion" (as it is called in the zsh man page). Similar solutions are available for bash and other shells as well (you did not specify ...


-1

I tried: for zip file: zipgrep -s "pattern" *.zip for .gz file zgrep "pattern" .* Note: zgrep use same option as grep.


1

If somebody is changing files remotely without authorization, you have very serious security problems. You should disconnect the machine from the Internet, back up only configuration and data files, go over them with a fine comb to make sure nothing is fishy, reinstall from scratch, make sure you aren't running any vulnerable programs (specially ...


1

To monitor user login history you can try Utmpdump . It will give you users,times,ipaddresses of logins to display the contents of /var/run/utmp, run the following command: utmpdump /var/run/utmp To do the same with /var/log/wtmp: utmpdump /var/log/wtmp And with /var/log/btmp: utmpdump /var/log/btmp you can use the following command to list all ...


1

Not likely in one step, but you can see who logged into a system using w and you can match the modification times of the files shown by stat with the logged in time of the user. If the file isn't 777, you can also consider the permissions of the given user to filter this down to only people able to edit the file. Otherwise, look into auditing file system ...


1

The recode program can do this quickly even for large files, either frequency statistics either for bytes or for the characters of various character sets. E.g. to count byte frequencies: $ echo hello there > /tmp/q $ recode latin1/..count-characters < /tmp/q 1 000A LF 1 0020 SP 3 0065 e 2 0068 h 2 006C l 1 006F o 1 0072 r 1 ...


0

using awk -- echo "{"user":"abcd","Name":"mike","middlename":"B","Lastname":null,"userid":"1234","Birthdate":"01-Jan-1800"}" | awk 'BEGIN {FS=","} {for(i=1;i<=NF;i++) {split($i,a,":"); val=a[2]; gsub("{|}","",val); print val}}' abcd mike B null 1234


0

WordGrinder lets you view .odt files (text content only, naturally) in the console:


2

In places that expect a path to a file, ./foo is equivalent to foo. There are only a few places where writing ./foo is useful. Writing ./foo is useful when what is expected is not necessarily a path, but possibly a file name that may be looked up in a search path. The most common case is when invoking an executable command. Executable programs are searched ...


1

The command du is intended to show disk usage. Disk usage for a directory includes the size the actual directory takes. A directory is a special type of file that holds the names and inodes of all the files or other entries in it. This takes up disk space. For example, I have created three directories. One is dir1, which contains a single file sized 40M. ...


0

Try this tar -cf file.tar X.txt Y.txt Z.txt This will create file.tar you can run the below command to see the output vim file.tar eg: tar -cf file.tar X.txt Y.txt Z.txt vim file.tar " tar.vim version v29 " Browsing tarfile /root/file.tar " Select a file with cursor and press ENTER X.txt Y.txt Z.txt Shown is the ...


0

If you want file names of text files, ls *.txt > file_name_output.text If you want to get file contents together, cat *.txt > file_content_output.text


0

ls >> Out_file.txt When you are in concerned folder of course...


2

Well, you can omit the dot caracter for folders if you wish but the both are OK cd ./bar or cd bar are equivalent - but you'll agree that the second is more convenient. If you want to execute your bar.txt file (which may be executable with chmod 755 for example) then you have to use the ./ indicator ./bar.txt will execute the script bar.txt will do ...


0

This server is a legacy server with light use, hence so many DBs/tables. In short, what it happened is that the upgrade from the 5.5 MySQL Debian Jessie official package to the 5.6 MySQL Oracle´s deb raises the limit of the files open for table caching. Whilst the open table cache is by default 512 in 5.5, in 5.6 seems to be at least 2048. Evidently, the ...


0

interesting question - you could set a variable then use cut to parse the data and prepend the output with the content of your variable - via awk. (perhaps builtins exist to do this.. though the above will work). x=$target cat $file | cut -d" " -f2- | awk '{print info,$0 }' info=$target


1

awk doesn't have the capability to make in-place substitution like the newer versions of sed. So, you need to direct output to a different file and get it back from this newly created file, as seen below: awk '{$1="0.05"; print $0}' initc > initc.new && cat initc.new > initc


1

An awk solution: awk '$0!~/.*[[:alpha:]][[:digit:]]+$/ && $0!~/^[[:digit:]]+[[:alpha:]]+/' words.txt 789 hello he11o 88888


3

You can do it with find like so (to stay close to your original command) sudo find /mnt/sdb/ -type f -exec shred -v -n 1 {} + You should run it without -exec first so you can verify the list of files. However, if you've already removed files using regular rm, or overwritten files by editing or copying them, those files may still exist in the "free" space ...


1

To actually edit the source file and create a new file with the discards is a bit trickier. I would do this $ cat file 789 hello 1hello 112121hello3323 he11o hello9 88888 $ perl -i -lne 'if (/^\d+\D|\D\d+$/) {warn "$_\n"} else {print}' file 2>file_nums $ cat file 789 hello he11o 88888 $ cat file_nums 1hello 112121hello3323 hello9 The matched lines ...


2

GNU grep grep -vP '^\d+\D|\D\d+$' produces 789 hello he11o 88888


2

Use comm first sort the files: sort file1 -o file1_sorted sort file2 -o file2_sorted Of course you can use sort file1 -o file1 To sort in-place then use comm as following: comm -2 3 file2_sorted file1_sorted > newfile comm compares sorted files Or if your shell supports process substitution (bash, zsh and some kshs): comm -23 <(sort file2) ...


2

Aside from home directories, there are three directory hierarchies with writable data: /etc, /tmp and /var. /etc contains system configuration files, most of which are typically not sensitive. But there can be sensitive data there, e.g. wifi passwords. /tmp can potentially contain sensitive data; just about any program might put temporary files there. This ...


2

With prename: Setup: $ mkdir test && cd test $ > "foo bar XXX doo par.jpg"; > "foo bar YY YY doo par.jpg" Action: $ rename -n 's/^foo bar //; s/ doo par(\.[^.]*)$/$1/' * foo bar XXX doo par.jpg renamed as XXX.jpg foo bar YY YY doo par.jpg renamed as YY YY.jpg (Remove the -n to have those moves actually performed)


3

If the filename is in a variable, the canonical way to remove a preffix is: removepre="foo bar " filename="foo bar XXX doo par.jpg" filename="${filename#"$removepre"}" echo "$filename" The problem with the suffix you present is that there is an extension that you want to preserve, so it becomes a bit longer: removesuf=" doo par" filename="foo bar XXX doo ...


2

If you want to chown the directories only (and not the subfiles), use find -exec, as like: find -type d -name objects -exec chown myUser {} \; Going through this: -type d selects only directories -name objects looks only for directories named exactly "objects" -exec chown myUser {} \; executes chown myUser {} for each path found (with {} replaced by the ...


1

Use bash option globstar to traverse through any depth by **. While at codeRepo: shopt -s globstar chown myUser REPO1/AREA*/**/objects For preciseness, if there is only one digit (character) after AREA in the name, use ? to indicate a single character: chown myUser REPO1/AREA?/**/objects Likewise, for two characters: chown myUser ...


1

You almost answered your own question.. the answer is to use the recursive option -R run the command sudo chown -R richie codeRepo/ (assuming your username is richie) This will recursively set each file/folder to you as the owner, but does so; as far down the tree as it can get so is more of a sledgehammer approach.


0

To access the files on a disk, you need to mount the partition where they're stored. Mounting attaches a storage area to a directory; after mounting, the files in that storage area are accessible under that directory. Once the storage is mounted on a directory, just navigate to that directory in Filezilla. fdisk is telling you that the external disk is ...


3

Depending on the user you are using, you may need to type su - or sudo first to get root privileges. Type lsblk: > lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 111,8G 0 disk ├─sda1 8:1 0 1020K 0 part ├─sda2 8:2 0 41G 0 part ├─sda3 8:3 0 11G 0 part ├─sda4 8:4 0 19G 0 part / ├─sda5 8:5 0 ...


0

Those are used by semodule which is a tool used for managing SELinux policy modules. Operations are basically installing/removing, upgrading or listing modules. You can also use semodule to force a reload of policy without performing any other transaction. semodule acts on module packages created by semodule_package. Conventionally, these files have a .pp ...


2

Your sed command only sends its result to the standard output. You would have to redirect it in a subsequent command (NOT in the same command, like sed 'sedcommand' file > file, as this would erase the file before processing it). You also can pipe the commands to ed instead of using sed : for file in $filelist ; do echo -e ...


6

Try this: sed 's/yyyymmdd/YYYYMMDDHH24MISS/g' filename > changed.txt Or, to keep the same filename: sed 's/yyyymmdd/YYYYMMDDHH24MISS/g' filename > changed.txt && mv changed.txt filename


2

Your file stills there. You only changed the file's path and name since you only execute mv and not rm command. Your original file must be in /fullchain.pem. You moved the fullchain.pem file from its original path /etc/letsencrypt/live/fullchain.pem to / that's why you can't see it any more in the main. Just execute $ mv /fullchain.pem ...


2

Since you're trying to match the first 30 lines of your files you could save the text in a file e.g. ref_file then use diff to compare the reference file with the first 30 lines in each file: find . -name "*.[ch]" -exec ./myscript {} \; -print where ./myscript is #!/bin/sh head -n 30 "$1" | diff - /path/to/ref_file >/dev/null so -print in the first ...


2

You could find each file to be processed using find and feed each filename to a script made on purpose to look for a match and print the filename in case of a match; I'd suggest to use a script rather than a one-liner for the added easiness of handling the multi-line string compared to the prompt. That is: find . -name "*.[ch]" -exec /path/to/script {} \; ...


4

Here is a solution built around the inotifywait utility. (You could use incron too, but you'd still need code similar to this.) Run this at boot time, for example from /etc/rc.local. #!/bin/bash # cd /path/to/samba/folder # Rename received files to this prefix and suffix prefix="some_prefix" suffix="pdf" inotifywait --event close_write --format "%f" ...


0

I think cron is a good idea! Here some input for your script: #!/bin/bash smbdir="@sambadir@" # change the @sambadir@ variable by hand smbsubdirs=(A B C D) smbprefix="@sambaprefix@" # for example for sd in ${smbsubdirs[@]}; do ssd=$smbdir/$sd && [ -d "$ssd" ] || continue for f in $(find $ssd -cnewer $ssd -type f); do if [[ "$(basename $f)" ...


0

This answer borrows ideas from this other answer and this other answer but builds on them, creating an answer that is more generally applicable: num_bytes=$(sed '/myregex/d' /path/to/file/filename | wc -c) sed '/myregex/d' /path/to/file/filename 1<> /path/to/file/filename dd if=/dev/null of=/path/to/file/filename bs="$num_bytes" seek=1 The first line ...


0

I believe you wrote the .cpp file on the Linux server, and now you want to get the file from the Linux server to your home computer, and then from your home computer so that you can submit it to your class's website. To get the file from the Linux server, first find out where the file "lives". So, whilst SSH'd into the Linux server, do this: $ readlink -f ...


2

You have created an "infinite loop" with a softlink that points to itself. You may have mixed up the arguments to ln. Since the second argument to ln is an existing directory, it will create a softlink with the same "base name" as the first argument, inside that directory. So you create a softlink ROOT which points to ROOT. When trying to resolve this you ...



Top 50 recent answers are included