Tag Info

New answers tagged

0

With awk: $ awk 'BEGIN{FS=OFS="|"}NR==FNR{a[$1]=$0;next}{$1=a[$1]}1' file_1 file_2 14595|Age 35|Salary xx|Position ax|2013|Info 1|Info 2|Info 3|Info 4|Info 5|Address xx|Info 6|Info 7|Info 8 14649|Age 30|Salary xx|Position az|2015|Info 1|Info 2|Info 3|Info 4|Info 5|Address xxxz|Info 6|Info 7|Info 8


2

Use join: $ join -t'|' file_1 file_2 14595|Age 35|Salary xx|Position ax|2013|Info 1|Info 2|Info 3|Info 4|Info 5|Address xx|Info 6|Info 7|Info 8 14649|Age 30|Salary xx|Position az|2015|Info 1|Info 2|Info 3|Info 4|Info 5|Address xxxz|Info 6|Info 7|Info 8 -t indicates the field separator. In order to join works, files must te sorted. You can use sort for ...


1

Instead of cp -r usr/* /usr, do: cp -ri usr/* /usr The -i flag will make the copy process interactive and will ask your permission if it will overwrite any files. You will have an option either to grant or not to grant the permission. P.S:- The version of cp on my test server is 8.4. It does not ask for permission before over-writing files unless I use cp ...


0

No it won't. It will only write over files that exists in both locations or copy new ones leaving old files in the destination alone.


2

You can use the touch command to create empty files. With crazy names like that, it's essential to quote them properly. touch ";rm *;.jpg" ";rm -rf *;.jpg" If you create files named like that on my machine your life expectancy will be very short. :)


1

Google is often the quickest way. However, if you want to search man pages, you can use the following to list (-w) all man pages of user commands (section 1) containing the text .bashrc anywhere: man -w -s 1 -K .bashrc For a file like .bashrc, this will turn up a few false positives in the form of man pages that suggest adding an alias or other setting to ...


0

I recommend @akrafs answer, but if that is not detailed enough; you can set up auditd to log which file accessed the configuration file. More details in : http://www.la-samhna.de/library/audit.html


0

This should get all the words from all the files, sort them and get unique words, than iterate through those words and count how many files it occurs in. # find all words from all files within the directory grep -o -h -E '\w+' directory/*|sort -u | \ while read word; do # iterate through each word and find how many files it occurs c=`grep -l ...


1

If you have a package manager, you can query, which package owns a given file. On Arch Linux, you can use pacman -Qo FILENAME On Ubuntu, Debian and other distributions with apt, you can use apt-file FILENAME To search man files, you can use zgrep cd /usr/share/man find -name *.gz | \ # List all *.gz files while read line; do # For each ...


0

I think you want to search for those files that start with data and then following by any three character (XXX) which is ends with .csv, right? So you can use grep with find command: find . -maxdepth 1 -type f -printf "%f\n" |grep -c '^data...\.csv$' . refer to current directory. -maxdepth 1 looking for files only in current directory(maximum 1 level). ...


0

Using find to test that they are a file (-type f) and match the required pattern ("data*.csv"): find directory/ -type f -name "data*.csv" | wc -l


0

There are probably fancier ways, but what works for me is ls /directory/data* | wc -l


0

If your distro packages the ifconfig_selinux man page (Fedora has it in selinux-policy-devel), it'll tell you: The following file types are defined for ifconfig: ifconfig_exec_t - Set files with the ifconfig_exec_t type, if you want to transition an executable to the ifconfig_t domain. Paths: /bin/ip, /sbin/ip, /sbin/tc, ...


0

Edit: oops, sorry, I didn't saw that this topic was pretty old. Oh well, it can help other people.. I will complete rahmu's and MV's answers with a technical solution. Finding the web server username Firstly you will need to know the username under your web server runs. If you are using Apache, it can be apache or httpd, www-data, etc. On most Debian-like ...


7

rm [0-9][0-9].* will do it for files in the current directory (no quotes — you want to match files). The . doesn't need to be escaped, because this is a shell glob and not a regular expression (if it were a regex, that would be a wildcard). If you are looking to do this recursively, find is probably your best bet.


5

Recursively : find . -type f -name '[0-9][0-9].*' -delete require GNU find, or : find . -type f -name '[0-9][0-9].*' -exec rm {} \;


1

The following uses data.csv as a link to the requested file to keep status between iterations. # check to see if an argument is given if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" exit fi # check if ran before if so move that to processed/ directory if [ -h "data.csv" ]; then prev=`readlink data.csv` echo ...


0

I think the option user users or group while mountig will do it: mount /dev/sdx /<mountpoint> -o user=<myuser> or simmilar with the other options.


1

If the file names have no newlines, you can find the first file to process in a bash script by using: first=$(ls --sort=version *.csv | head -1) ln -s "$first" data.csv however before you rename that file you have to make sure and old existing one is out of the way: #! /bin/bash if [ -e data.csv ] ; then mv $(readlink data.csv) backup_directory rm ...


4

Hold buffer method: sed '$x;1!H;1p;$!d;x;s/\n// ' <<\IN aaaaaa bbbbbb cccccc dddddd eeeeee IN ...that will Hold every line which is !not the first, and the first it prints. On the $last line it exchanges hold and pattern spaces before it does the Hold - which gets the saved lines appended to the last line - then deletes from output all lines which ...


8

This problem might actually be easiest to do with ed, since it's a basically a scriptable text editor, rather than a stream processor. Using ed, you don't have to save all the lines of the file into an array, for instance, since it's already doing that for you. # Create test file ~> printf "%s\n" aaaaaa bbbbbb cccccc dddddd eeeeee >test.txt ~> cat ...


1

With perl : perl -e 'my @lines = <>; print for @lines[0, $#lines, 1..$#lines-1]' file With awk : $ awk ' {lines[NR]=$0} END{ print lines[1], lines[NR]; for (i=2; i<NR; i++) {print lines[i]} } ' OFS=$'\n' file OUTPUT aaaaaa eeeeee bbbbbb cccccc dddddd


2

A naive approch using awk: ~$ awk '{a[NR]=$0}END{print a[1];print a[NR];for(i=2;i<NR;i++){print a[i]}}' f aaaaaa eeeeee bbbbbb cccccc dddddd You store every line in the a array, then print the array in the order you want (1st line, last one (NR) and from 2 to penultimate. Using a combination of head/tail and sed: ~$ head -1 f;tail -1 f;sed '1d;$d' f ...


0

If you have files in a folder, you want to hide, you can simply add . before the name and are able to see them in a file manager using some keyboard shortcut to display hidden files (ALT + . for example).


1

There is a split command: ~$ split --help Usage: split [OPTION]... [INPUT [PREFIX]] Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT is -, read standard input. ... -n, --number=CHUNKS generate CHUNKS output files. ... CHUNKS may be: N split into N ...


-1

Traditionally, this is done with rexec. For example: rexec mymachine.batcave.ucsd.edu export DEBIAN_FRONTEND=noninteractive rexec mymachine.batcave.ucsd.edu apt-get update -q rexec mymachine.batcave.ucsd.edu apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" ssh would install ssh on the remote machine ...


4

Detecting UTF-8 encoding: file will usually give you the encoding; to get a more processable output from file, you've got to pass some options, and cut it until you get the part that describes the encoding: file --brief --mime myfile.txt | cut -d '=' -f 2 Note that it may either be 'us-ascii' or 'utf-8', depending on whether it finds some UTF-8 ...


4

A simple workaround would be to use dropbox, or any type of software that lets you sync between linux and windows (also see Unison and BitTorrent Sync). If you have dropbox running in both computers, then your work folder will be synchronized almost instantly. This way you can have the updated pdf in a few seconds after compiling.


0

You should try the file command, it already does a good job of determining information about the contents, although it doesn't analyse the full data file. If you have a large file somefile where the first utf-8 character doesn't appear until the end, file somefile will not detect that as an utf-8 file.


3

Yes it is possible, but there are multiple steps involved: You must be able to reach your home computer running Linux from the internet. This means opening up port 22 (ssh) or your router at home, or a higher port if your provider blocks incoming access on ports below 1024. Then install openssh-server (and make it listen on any non-default port). You also ...


8

If you can install software on your work computer, then you could install win-sshfs and a ssh client such as PuTTY on your Windows machine. You can then ssh into the remote Ubuntu server to run LaTex and create your files, after which you could use win-sshfs to access those files from the Windows machine. This way, you'd only need the one ssh port open on ...


1

Use software like teamviewer to remotely access your Ubuntu machine. http://www.teamviewer.com/en/index.aspx


5

You can run a program from your home computer over SSH. The application will still run on the computer at home but be streamed over the internet. This can be done via X forwarding. An X forwarding tutorial can be found at the following 2 URL's; https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding ...


1

Tried to write a Bash script. Please check if it can help you out. #!/bin/bash NOW=`date +%s` last_day() { case $MM in 01|03|05|07|08|10|12 ) echo "31" ;; 04|06|09|11 ) echo "30" ;; 02 ) echo "28" ;; esac } for file in `ls -1 bkp*` do # echo $file DATE=`echo $file | tr -cd [0-9]` # Extract Day of the Month from file name ...


1

I think you do not need to rename the files. You can transform the the filenames on the fly (first sed), compare them to a date (awk) and transform the matching filenames back (second sed). find parent/directory -maxdepth 1 -type d -name 'bkp_*' | \ sed 's#parent/directory/bkp_\(..\)\(..\)\(....\)#\3\2\1#' | \ awk -v date=$(date ...


0

I created a script that will do this. The script converts all hard-links it finds in a source directory (first argument) that are the same as in the working directory (optional second argument) into symbolic links: https://gist.github.com/rubo77/7a9a83695a28412abbcd It has an option -n for a dry-run, that doesn't do anything but shows what would be done. ...


0

This is not impossible, but as @tkausl has suggested it involves searching the whole partition, unless you have some other knowledge of possible locations. If there are more than 2 links to the file there is no way to identify the "original" file. I have written programs to find all hardlinks which have the same target. This is certainly NOT a task to be ...


0

I came by here, but I was needing to copy files in parts (99 each) from /DIR1 to /DIR2. I'll paste the script here to help otherz maybe: #!/bin/bash # Thanks to <Jordan_U> @ #ubuntu # 06 Dec 2014 i=0 copy_unit=98 for file in /DIR1/*; do cp "$file" /DIR2 if [[ "$i" -ge "$copy_unit" ]]; then echo "Pausing, press enter to continue" read ...


1

Why not just scan the directory with a cron job entry using the find command. Then delete a file that is older than X minutes. I wouldn't think that having a periodic run of maybe every 15 minutes would be any sort of strain on the system and it would run all the time.


4

You don't need the cat. sed happily accepts the file name as argument: sed 's/^ *//' <file> If you use GNU sed you can use the -i or --in-place switch to edit the file in place: sed -i 's/^ *//' <file> To answer the question, you can achieve “full file buffering” using the tool sponge from the moreutils package. Using sponge you can do: ...


0

Useless use of the cat command. Use sed directly to print the contents or use -i to do an in place edit.


0

One other possibility is to put the entire contents of a file into a shell variable. There used to be a limit on the size, but I understand that this is no longer a problem. As long as you have the memory (of course exceeding physical memory would cause swapping) you can try the following: For example: varx=`cat filename` echo "$varx" | sed ..... ...


0

Have you looked at the Linux buffer command? This utilizes a user shared memory segment to basically allow concurrent reads/writes. I suppose that it could buffer an entire file if the shared memory segment is large enough. The buffer command might not be automatically installed, but I have found the program in many of the repositories on different Linux ...


0

You simply have to use -i switch of (GNU) sed, so sed -i -r 's/^ *//' file_to_replace_in_place.txt and for Os X : sed -i.'' -r 's/^ *//' file_to_replace_in_place.txt Another (more generic) solution is to use tee : cat file | sed 's/^ *//' | tee file you have to take care of huge files, this can exit without error, nor change.


4

There are 3 avenues that I can conceive of that might provide you with a solution. 1. Custom sftp Subsystem You could wrap the sftp-server daemon via sshd_config and "override" it with your own script that could then intercept what sftp-server is doing, and then act when you see that a file was downloaded. Overriding the default sftp-server in sshd_config ...


-1

If you know the path and name then you can do this if [ -f $filename ]; then archive else echo "" fi However you did not add any such information.


2

Configure the SSH server to log the activity, then you can parse the log to know if such file has been downloaded. To enable logging append -l INFO to the sftp subsystem line in the /etc/ssh/sshd_config file, it should look something like (the path may vary by distro, I'm using SuSE 11): Subsystem sftp /usr/lib64/ssh/sftp-server -l INFO Now the ...


2

Since you already do mention PuTTY, you already have all you need to find out how to solve the problem. You have several options. One is using an SSH client (e.g. PuTTY) to connect to the server, running: $ cat > path/to/resulting/file <<EOD ... your pasted text goes here ... EOD or just using a SCP client to just copy the file there. With pscp ...


0

Sounds like you've got access to the server using putty (going over ssh). That gets you logged in. After that just start vim, paste in the content as you would have done in noMachine (paste in putty is just right-click - at least for me). Then save the file from within vim. I'm not sure if I'm missing a complication of your setup since this sounds very ...


3

Needing only one command is a hard thing to achieve with unix philosophy in mind. On the other hand: you can rule major parts of your world using one-liners. First fix the configuration files in sites-available with the script from the question, then use the following code to create new symlinks in sites-enabled. cd /etc/apache2/sites-enabled find . ...



Top 50 recent answers are included