New answers tagged

2

In general, to log the output of the entire script, redirect the output of the entire script: exec &> some.log # Or, when using `/bin/sh`: # exec >some.log 2>&1 The exec builtin is often used to change the open file descriptors or add new file descriptors (the sources and destinations of input and output) for the shell. For example, ...


0

Thanks guys, I tried this code and that worked fine for me, !/bin/bash DPATH="/root/test.txt" k=$(grep 'web' $DPATH | awk '{print $2}') # web ends by a number# i=$(grep 'web' $DPATH | awk '{print $2}'| cut -c3) m=$((i+1)) n="web-client$m" sed -i -e 's/'"$k"'/'"$n"'/g' $DPATH


2

No there is not one of such tools. Different graphical tools will perform specific command line instructions. Like "software updater" handles apt-get instructions you also have ... "Task manager" that handles processes (command "ps"). You can view process, changes niceness, kill a process etc. "Nautilus" that handles file manager commands. Like "ls", ...


0

This makes no sence. A terminal is something where you type into and not where you click on something. There are millions commands it wouldn't even possible to make it graphical. But the more general things can be managed through Ubuntu's settings witch are graphical. If you just need it for managing packages there is synaptic or you could also use the ...


0

Solution for this is to use Terminator, an Linux terminal: Terminator Also here is a tutorial how to do this: Right click paste on linux terminal with terminator


3

No need for a script, just do it in one line using Bash redirections and tee: (sudo apt-get update && sudo apt-get upgrade) 2>&1 | tee output.txt In case you want to append the output to an existing logfile, add the -a option after tee. To explain what it does: (...) groups the commands inside, so that the output redirections we will ...


4

If I understand your question correctly, you can use the following: #!/bin/bash apt-get update &> update.log apt-get -y upgrade &> upgrade.log echo "all done" Save this script as run_updates.sh, make it executable with chmod 755 run_updates.sh and run it with sudo ./run_updates.sh. If you want to save all output in one file, remove the ...


3

Well you mentioned apt-get commands, so You could just use Ubuntu update-manager (that's more or less gui for apt-get) and I'm pretty sure there are others like synaptic for example. On the other hand, there is no such thing that You are describing for ALL commands acessible from terminal (imagine, my ls /usr/bin | wc has 2186 entries, and that's not all ...


1

If you don't have line breaks in your file or folder names you should use a ´whileinstead of afor` loop: find -iname "*.wmf" | while read file; do uniconvertor "$file" "${i%.wmf}.svg" done This avoids problems with spaces in names and with too much arguments when expanding the `...`


0

You must surround your find ... command with $( ) to substitute the output, thusly: for i in $( find . -type f -iname '*.wmv` ) ; do ... However, you're causing Bash to produce (and store internally) a list of 120,860 filenames before you process the first one. Also (you haven't described the format of the filenames), this technique mishandles filenames ...


2

All "processess" that are active can be seen with the "ps" command. From command line you can type ... ps -ef | grep phpstorm it will list all the process IDs $ ps -ef| grep phpstorm rinzwind 2819 2812 0 11:28 ? 00:00:00 phpstorm rinzwind 2849 2820 0 11:29 pts/1 00:00:00 grep --color=phpstorm The line with the "grep" is what you search ...


0

If you are using btrfs, it is possibly an empty directory with a non-zero i_size. You can check whether this is the case with: stat -c %s test The i_size of an empty folder in btrfs should be zero. In my case, I got 6160 with ~/.config/chromium/Default. The suggested solution is to unmount the filesystem, run btrfs check to confirm the issue and check ...


1

There are 3 decent choices: You could create a script something like the following: #!/bin/bash set -e sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade Call it something like update.sh and place it in /usr/local/bin and then run: chmod +x /usr/local/bin/update.sh Another method would be to create a bash alias (in ~/.bashrc) or ...


1

The -R option will run that command on each and every file/folder it finds below your current folder. run chmod go-w -R from wherever you ran that command for safety; and stop other users/groups re-writting any files that don't belong to them. In most cases this is OK but you may have to edit specific files if you have problems, I just hope you didn't run it ...


0

When using Bash scripts in crontab you should declare the SHELL variable first: SHELL=/bin/bash The Shebang header is not needed.


3

AWK can search and replace text as well, so there is no need to use grep or sed. The code bellow extracts substring from second column (webN), increments N, and substitutes second field with webN+1 $ cat testInput.txt project web0 other project web1 $ awk '/web/{ ...


3

Using Perl: perl -pe 's/\bweb\K[0-9]+\b/$&+1/ge' file To edit the file in place, add the -i option: perl -i -pe 's/\bweb\K[0-9]+\b/$&+1/ge' file -p: causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed: LINE: while (<>) { ... # your ...


2

First of all i want to thank @incBrain and @Serg for not answering my question directly which helped me understand a lot of new things :). My task was finding a specific .jpg file that has it's extension removed, the first thing I though of is .jpg magic byte which was JFIF, and with @incBrain Instructions I was able to build this command find / -exec ...


2

Copy your personal data which you want to keep to another drive. Download an Ubuntu edition and create a DVD/USB install media. Boot from Ubuntu installation media. Select 'Try Ubuntu without installing'. On Ubuntu Live desktop open GParted. Format the Ubuntu partition with ext4. On the desktop click Install Ubuntu, choose Something else. Select the ...


2

You need to install several packages namely as follows postfix mailutils libsasl2-2 ca-certificates libsasl2-modules these packages are required for the proper setup of mail sending. Here is a proper way of setting this up and testing out by sending mail and the possible troubleshooting. Hope this helps :)


0

If you want to not load the alias every time, to permanently store a alias command, do this. Go to your home directory and press Ctrl+H to view hidden files, one of these files would be .bashrc. Open it. Now write the following command anywhere in the mainspace: alias custom_command='original_command' Your shortcut command will be stored permanently.


2

Yes! Linux has killall. Try killall firefox. But my favorite is command line task manager htop - run that, press F5 for process tree view and kill necessary process. Well, actually process killing is bad. You have to have pretty good reason to do that. Try to find source of problem.


3

The way to find the problem: run.sh is a script. So do a more run.sh to see what is on the line number is shows in the error. The line will start with a command (java most likely). Do a java --version. If this errors out you did not install "java" and the program depends on it. sudo apt-get install openjdk-8-jre would install Open JDK 8 and make the ...


-1

Try running this commands: chmod 755 xampp-linux-*-installer.run sudo ./xampp-linux-*-installer.run I had the same problem, this fixed mine.


0

From the command line : Install the Labeling Program Based on the package names listed above for each filesystem type, install the correct package for your partition: sudo apt-get install <package> Here are all the different ones: sudo apt-get install mtools sudo apt-get install ntfsprogs sudo apt-get install e2fsprogs sudo apt-get install ...


3

You can re-label file systems with Gnome Disks: If you really want to use the command line, the command depends on the affected file system type. For ext2/3/4 it's sudo e2label <DEVICE> <NEW_LABEL> In a similar fashion there are fatlabel, exfatlabel, ntfslabel, btrfs filesystem label, swaplabel for other file system types with the same ...


0

While you can use the method of allowing NOPASSWD on /usr/sbin/shutdown, although another, DE-independent solution is to just use init 0.


1

I know it's an old question, but nobody mentioned peerflix. Written in JavaScript, works great, super simple to use, has a nice, informative and colored interface. Most importantly, it supports streaming of video and audio content through VLC (just launch it with the flag --vlc).


-1

You can also add the following line to your .bashrc: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\`__git_ps1`\$ '


1

I do not think there is a much more efficient way then finding files and execute a single instance of rsync. Any attampt to pipe a list of files into rsync will result in a maintained directory structure. One alternative (if you can constraint the find pattern) is to use: rsync -d --delete --include=*.pdf --include=*.ods --exclude=* ...


2

A simple way to check why a package has been updated is to check its changelog. apt-get changelog pkgname For example, here is the current changelog for openssh-client $ apt-get changelog openssh-client openssh (1:5.9p1-5ubuntu1.8) precise-security; urgency=medium * SECURITY UPDATE: information leak and overflow in roaming support - ...


-1

Add this one liner to the .bashrc: export PS1='\u@\h \W$(__git_ps1 " [ - %s - ]") \$ '


2

If you want to live track the processes you can have the famous command: top but you want it by filename so you will need to add a parameter as: top -c


2

EDIT Since you've asked how to check if a process is running or not when you know its name , then it's a simple pgrep operation. Alternatively, one could use ps and specify state options for formating $ ps --no-headers -C firefox -o args,state /usr/lib/firefox/firefox R State code is on the right. From man ps you can know their ...


0

less is a pretty useful command evolved from more. You can use it to browse through large text files. Run: less $HOME/.bash_history Use the Up/Down arrow keys to go up and down in the file. Press q to exit. For more information/keyboard shortcuts in less, run man less. It will show its manual pages. For instance, you could also use other utilities, such ...


0

$history and it will show the history 1999 exit 2000 cd /opt 2001 sudo apt-get install p7zip-full 2002 sudo apt-get install p7zip-rar 2003 mkdir CS-RT-code 2004 cd CS-RT-code/ 2005 ls -lrt 2006 history $ !<history #> to execute the previous history command


10

I'll try to give you some hints so you can solve your HW yourself. Follow this steps: read the manual of file by executing man file. Then try it out by file somefile and see what happens Try to run file on different file types By now you should be able to understand how to find out if some file is a jpeg image or not. now read the manual for find (or use ...


2

One possible solution could be this: use find which recursively lists regular files (-type f), and performs file command upon each one of them. Redirect output to grep to filter out filetypes. However here, I would like to do something more fun than that; more awkward , but more fun. $ find . -maxdepth 1 -type f -printf "%f\t" -exec hexdump -n8 {} \; | ...


1

You could combine the find command with gunzip like so: find . -type f -iname '*.gz' -exec gunzip "{}" \; Make sure you do this from the /home/account/www directory, or use this command find /home/account/www -type f -iname '*.gz' -exec gunzip "{}" \;


0

For data synchronization, you should take a look at rsync. Running scripts will require setting up SSH on the laptops, then you need to log in on them, and run the scripts on each machine.


2

Nothing's wrong with tee. Python buffers output if it detects it's not writing to a TTY. See this Unix & Linux post. Use sys.stdout.flush() to force flushing the buffer.


1

You can make an alias for date in .bashrc by typing alias date=date +%r and then doing source .bashrc, if you want to change date default format.


1

Your problem there are in locale configurations your system . Type this to fixed your problem first run locale generate the missing locale and reconfigure locales sudo locale-gen "en_US.UTF-8" && sudo dpkg-reconfigure locales see more : How do I fix my locale issue?


0

Follow this step ; Open the terminal If you don't have a .bashrc file in your $HOME (/home/<username>) , make it with type this command touch $HOME/.bashrc If you have it, open it with text editor like nano, etc. add this script in your .bashrc PS1='[ \h \W]\$ ' To make your hostname such as you want open file /etc/hostname with sudo sudo nano ...


0

who then sudo kill PID PID is the four digit number at the end of the user readout


0

Yes, it is possible. But first, you may want to define which data you want to sync. You can write a simple bash script that copies all the desired files from one computer to another (you should consider using SSH-keys to avoid entering the user's password every time that you want to coy files). My approach would be to have a menu with the option "copy data ...


0

Not exactly what was asked for... but much easier to remember... ls -alRt docroot or ls -alRt /path/to/top/level/directory


0

You can see the list of running programs after you ssh by running top or ps. The set of programs run at startup is usually found in .profile or /etc/profile. If the ssh shell runs bash .bash_profile or .bash_rc or /etc/bashrc may also contain instructions to run the programs. More detailed information about services is found in sudo service --status-all ...


0

Introduction to Linux course on EdX helped me a lot when I was starting. Here is a link to the course page. Edx or other similar platforms might be offering other courses on Ubuntu/Linux too.


0

Just as a complement to @souravc answer... For the "User level Change", instead of editing the ~/.bashrc file you can simply create the directory $HOME/bin/ and place your scripts in there. The directory will be automatically added to the PATH (at least since Ubuntu 12.04) which means that you'll be able to run all the scripts/executables inside that ...



Top 50 recent answers are included