155 Answered Questions for the topic Linux
Defining a variable with or without export?
What is `export` for?
What is the difference between:
export name=value
and
name=value
06/21/19
How to recursively find and list the latest modified files in a directory with subdirectories and times?
- Operating system: Linux
- Filesystem type: ext3
- Preferred solution: bash (script/oneliner), ruby, python
I have several directories with several subdirectories and files in them. I need to...
more
06/21/19
How to keep environment variables when using sudo?
When I use any command with sudo the environment variables are not there. For example after setting HTTP_PROXY the command `wget` works fine without `sudo`. However if I type `sudo wget` it says it...
more
Linux Shell
06/20/19
How can I recursively find all files in current and subfolders based on wildcard matching?
How can I recursively find all files in current and subfolders based on wildcard matching?
Get current time in seconds since the Epoch on Linux, Bash?
I need something simple like `date`, but in seconds since 1970 instead of the current date, hours, minutes, and seconds.
`date` doesn't seem to offer that option. Is there an easy way?
Linux Shell
06/20/19
Why doesn't "cd" work in a shell script?
I'm trying to write a small script to change the current directory to my project directory:
#!/bin/bash
cd /home/tree/projects/java
I saved this file as proj, added execute permission with...
more
How can I redirect and append both stdout and stderr to a file with Bash?
To redirect *stdout* to a truncated file in Bash, I know to use:
cmd > file.txt
To redirect *stdout* in Bash, appending to a file, I know to use:
cmd >> file.txt
To redirect both...
more
Linux Docker
06/19/19
Docker can't connect to docker daemon?
After I update my Docker version to `0.8.0`, I get an error message while entering `sudo docker version`:
Client version: 0.8.0
Go version (client): go1.2
Git commit (client): cc3a8c8
...
more
06/19/19
Clear a terminal screen for real?
Using the `clear` command on the terminal only fools the user into thinking the screen has been cleared...you can still see output from the previous commands when you scroll using the mouse. This...
more
How to append one file to another in Ubuntu Linux?
I have two files: `file1` and `file2`. How do I append the contents of `file2` to `file1` so that contents of `file1` persist the process?
What's the best way to send a signal to all members of a process group?
I want to kill a whole process tree. What is the best way to do this using any common scripting languages? I am looking for a simple solution.
06/12/19
120fps 720p footage with real time playback on Ubuntu? + editing?
I have a laptop with an i7 CPU, 1.73 GHz, 8GB RAM, Ubuntu 10.04 with an "ATI Mobility Radeon HD 5800 Series" graphics card. I have compiz enabled (which may be one of the culprits with the problem...
more
Linux
06/12/19
Recursively counting files in a Linux directory?
How can I recursively count files in a Linux directory?
I found this:
find DIR_NAME -type f ¦ wc -l
But when I run this it returns the following error.
> find: paths must precede...
more
What does set -e mean in a bash script?
I'm studying the content of this **preinst** file that the script executes before that package is unpacked from its Debian archive (.deb) file.
The script has the following code:
#!/bin/bash
...
more
How to have the cp command create any necessary folders for copying a file to a destination?
When copying a file using `cp` to a folder that may or may not exist, how do I get `cp` to create the folder if necessary? Here is what I have tried:
<!-- language:none -->
[root@file...
more
Get program execution time in the shell?
I want to execute something in a linux shell under a few different conditions, and be able to output the execution time of each execution.
I know I could write a perl or python script that would...
more
Where is my php.ini file located on the server?
A few years ago I installed Apache 2.2x and PHP 5.3.1 on a Linux server I maintain. I used .tar.gz's and built them as instructed (instead of rpms and what-have-you). And all was fine.
Today I...
more
06/05/19
How do I change permissions for a folder and all of its subfolders and files in one step in Linux?
I would like to change permissions of a folder and all its sub folders and files in one step (command) in Linux.
I have already tried the below command but it works only for the mentioned...
more
Linux Bash
06/05/19
Bash ignoring error for a particular command?
I am using following options
set -o pipefail
set -e
In bash script to stop execution on error. I have 100 of script executing and I don't want to check return code of the script.
But for a...
more
Shell command to tar directory excluding certain files/folders?
Is there a simple shell command/script that supports excluding certain files/folders from being archived?
I have a directory that need to be archived with a sub directory that has a number of very...
more
Why do you need to put #!/bin/bash at the beginning of a script file?
I have made [Bash][1] scripts before and they all ran fine without this at the beginning. What's the point of putting it in? Would things be any different?
Also, how do you pronounce `#`? I know...
more
Extract file basename without path and extension in bash?
Given file names like these:
/the/path/foo.txt
bar.txt
I hope to get:
foo
bar
Why this doesn't work?
#!/bin/bash
fullfile=$1
fname=$(basename $fullfile)
fbname=${fname%.*}
echo...
more
Given two directory trees, how can I find out which files differ?
If I want find the differences between two directory trees, I usually just execute:
diff -r dir1/ dir2/
This outputs exactly what the differences are between corresponding files. I'm interested...
more
How can I format my grep output to show line numbers at the end of the line, and also the hit count?
I'm using grep to match string in a file. Here is an example file:
example one,
example two null,
example three,
example four null,
`grep -i null myfile.txt` returns
example two null,
...
more
How to exclude a directory in find . command?
I'm trying to run a `find` command for all JavaScript files, but how do I exclude a specific directory?
Here is the `find` code we're using.
for file in $(find . -name '*.js')
do
java -jar...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.